GRAY_BTN_PUSH(100, 110, 144),
GRAY_BTN_DISABLE(208, 208, 208),
+ RED(255, 0, 0),
+
MESSAGE_BOX_TITLE_BG(111, 125, 149),
MESSAGE_BOX_TITLE_FONT(255, 255, 255),
MESSAGE_BOX_CONTENTS_BG(255, 255, 255),
public enum FontResources {
GRAY_BTN_FONT("btn_font", resizeDefaultFont(10)),
- // * Toolbal Layout
- // Main Title
- TITLEBAR("titlebar", resizeDefaultFont(10)), //$NON-NLS-1$
- // Device Name
- COMBO("combo", resizeDefaultFont(9)), //$NON-NLS-1$
- // Application Name
- DROPDOWN("dropdown", resizeDefaultFont(9)), //$NON-NLS-1$
- // Timer
- TIMER("timer", resizeDefaultFont(12)), //$NON-NLS-1$
-
- // * Tab Layout
- TAB_BUTTON_FONT("tab_button_font", setDefaultFontStyleAndSize(SWT.BOLD, 9)), //$NON-NLS-1$
-
- // * List Layout
- VM_BUTTON_TITLE_FONT("vm_button_title_font", setDefaultFontStyleAndSize(SWT.BOLD, 8)), //$NON-NLS-1$
- VM_BUTTON_FONT("vm_button_font", resizeDefaultFont(8)), //$NON-NLS-1$
-
- // * Detail Layout
- DETAIL_TOP_FONT("detail_top_font", setDefaultFontStyleAndSize(SWT.BOLD, 10)), //$NON-NLS-1$
- DETAIL_TITLE_FONT("detail_title_font", resizeDefaultFont(9)), //$NON-NLS-1$
- DETAIL_TITLE_FONT_BOLD("detail_title_font", setDefaultFontStyleAndSize(SWT.BOLD, 9)), //$NON-NLS-1$
- DETAIL_LABEL_FONT("datail_label_font", resizeDefaultFont(8)), //$NON-NLS-1$
-
// * Nomal button
BUTTON_FONT("button_font", resizeDefaultFont(9)), //$NON-NLS-1$
- // * Combo button
- COMBO_BUTTON_FONT("combo_button_font", resizeDefaultFont(8)), //$NON-NLS-1$
-
- // * About Dlg.
- ABOUT_TITLE("about_title", resizeDefaultFont(12)), //$NON-NLS-1$
- ABOUT_TEXT("about_text", resizeDefaultFont(9)), //$NON-NLS-1$
- DIALOG_BUTTON_FONT("dialog_button_font", resizeDefaultFont(10)), //$NON-NLS-1$
-
- // * Status bar
- STATUS_BAR_FONT("status_bar_font", resizeDefaultFont(9)), //$NON-NLS-1$
- STATUS_BAR_SUB_FONT("status_bar_sub_font", resizeDefaultFont(8)), //$NON-NLS-1$
-
- // * Radio button
- RADIO_BUTTON_FONT("radio_button_font", resizeDefaultFont(8)), //$NON-NLS-1$
-
- // * Tree view
- TREE_CREATE_FONT("tree_creaet_font", setDefaultFontStyleAndSize(SWT.BOLD, 9)), //$NON-NLS-1$
- TREE_HEADER_FONT("tree_header_font", resizeDefaultFont(9)), //$NON-NLS-1$
- TREE_ITEM_FONT("tree_item_font", resizeDefaultFont(8)), //$NON-NLS-1$
-
- // * not support
- TOOLTIP("tooltip", resizeDefaultFont(9)); //$NON-NLS-1$
+ MESSAGE_BOX_TITLE("msg_box_title", resizeDefaultFont(10)),
+ MESSAGE_BOX_CONTENTS("msg_box_contents", resizeDefaultFont(9));
String name;
Font font;
}
defaultFont = EmulatorManager.isMac()
? new Font(Display.getCurrent(), new FontData[] { new FontData(fontName, 11, SWT.NORMAL) })
- : new Font(Display.getCurrent(), new FontData[] { new FontData(fontName, 9, SWT.NORMAL) });
+ : new Font(Display.getCurrent(), new FontData[] { new FontData(fontName, 9, SWT.NORMAL) });
}
return defaultFont;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
-import org.tizen.emulator.manager.resources.ColorResources;
-import org.tizen.emulator.manager.ui.dialog.AboutDialog;
+import org.tizen.emulator.manager.renewal.resources.ColorResources;
import org.tizen.emulator.manager.renewal.resources.ImageResources;
+import org.tizen.emulator.manager.ui.dialog.AboutDialog;
+import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton;
import org.tizen.emulator.manager.ui.table.FontResources;
-import org.tizen.emulator.manager.ui.widgets.ImageButton;
public abstract class AbstractTableViewer {
private static final int BUTTON_MENU_WIDTH = 20;
makeTopComposite();
makeTableComposite();
- mainComp.setBackground(ColorResources.CHOCOLATE.getColor());
- topComp.setBackground(ColorResources.BLUE.getColor());
tableComp.setBackground(ColorResources.RED.getColor());
settingLayout();
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.tizen.emulator.manager.renewal.resources.ColorResources;
+import org.tizen.emulator.manager.renewal.resources.FontResources;
+import org.tizen.emulator.manager.ui.renewal.widgets.GrayButton;
import org.tizen.emulator.manager.ui.table.CustomScrolledComposite;
-import org.tizen.emulator.manager.ui.table.FontResources;
public class MessageBox {
private final int MIN_WIDTH = 300;
makeContentsBox();
// need contentsBox size
+ dialog.setBackgroundMode(SWT.INHERIT_FORCE);
dialog.setBounds(computeDialogBounds());
// need dialog size
titleLabel.setText(this.title);
titleLabel.setBackground(ColorResources.MESSAGE_BOX_TITLE_BG.getColor());
titleLabel.setForeground(ColorResources.MESSAGE_BOX_TITLE_FONT.getColor());
- titleLabel.setFont(FontResources.setSizeDefaultFont(9));
+ titleLabel.setFont(FontResources.MESSAGE_BOX_TITLE.getFont());
titleLabel.setLeftMargin(SPACING);
titleLabel.setTopMargin(10);
}
contentsBox.setText(message);
contentsBox.setBackground(ColorResources.MESSAGE_BOX_CONTENTS_BG.getColor());
contentsBox.setForeground(ColorResources.MESSAGE_BOX_CONTENTS_FONT.getColor());
- contentsBox.setFont(FontResources.setSizeDefaultFont(9));
+ contentsBox.setFont(FontResources.MESSAGE_BOX_CONTENTS.getFont());
contentsBox.setLeftMargin(SPACING);
contentsBox.setTopMargin(SPACING);
contentsBox.setEnabled(false);
private int buttonCount = 1;
private void makeButton(String text, final int buttonType) {
if ((style & buttonType) == buttonType) {
- Button button = new Button(dialog, SWT.PUSH);
- button.setFont(FontResources.setSizeDefaultFont(10));
+ GrayButton button = new GrayButton(dialog, SWT.PUSH);
+ button.setFont(FontResources.GRAY_BTN_FONT.getFont());
button.setText(text);
+ button.setBackground(null);
button.addListener(SWT.Selection, new Listener(){
@Override
public void handleEvent(Event event) {
});
button.setBounds(width - (BUTTON_WIDTH + SPACING) * buttonCount,
- height - (BOTTOM_HEIGHT + BUTTON_HEIGHT)/2,
- BUTTON_WIDTH, BUTTON_HEIGHT);
+ height - (BOTTOM_HEIGHT + BUTTON_HEIGHT)/2,
+ BUTTON_WIDTH, BUTTON_HEIGHT);
buttonCount++;
}
}
import org.tizen.emulator.manager.platform.ProfileList;
import org.tizen.emulator.manager.plugin.PluginImageResources;
import org.tizen.emulator.manager.renewal.resources.ImageResources;
-import org.tizen.emulator.manager.ui.widgets.ImageButton;
+import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton;
class ProfileButton {
private String profileName;
import org.tizen.emulator.manager.platform.Profile;
import org.tizen.emulator.manager.platform.ProfileList;
import org.tizen.emulator.manager.renewal.resources.ImageResources;
+import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton;
import org.tizen.emulator.manager.ui.table.Table;
import org.tizen.emulator.manager.ui.table.TableColumn;
import org.tizen.emulator.manager.ui.table.TableItem;
-import org.tizen.emulator.manager.ui.widgets.ImageButton;
import org.tizen.emulator.manager.vms.SKIN_SHAPE;
import org.tizen.emulator.manager.vms.VMProperty;
import org.tizen.emulator.manager.vms.VMPropertyValue;
this.comp = comp;
}
- public void setVMList() {
- for (ProfileButton pButton : profileButtonList) {
- if (pButton.getProfile() == null) {
- continue;
- }
- makeTableItem(pButton);
- }
-
- table.getColumn(0).setWidth(30);
- table.getColumn(1).setWidth(100);
- for (int i = 2; i < titles.length; i++) {
- table.getColumn(i).pack();
- }
- }
-
- String[] titles = {"", "Type", "Name", "Device", "Platform", "Resolution", "File Sharing"};
+ String[] titles = {"", "Type", "Name", "Device", "Base Image", "Resolution", "File Sharing"};
private void makeTable() {
table = new Table(comp, SWT.MULTI | SWT.CHECK | SWT.BORDER);
}
table.getColumn(0).setResizable(false);
table.getColumn(1).setResizable(false);
- table.addSelectionListener(tableSelectionListener);
+ table.addListener(SWT.Selection, new Listener(){
+ @Override
+ public void handleEvent(Event e) {
+ if (e.type == SWT.Selection) {
+ tableSelected();
+ }
+ }
+
+ });
}
private void makeProfileButton() {
}
}
+ private ProfileButton findProfileButton(String profile) {
+ for (ProfileButton pButton : profileButtonList) {
+ if (pButton.getProfileName().equals(profile)) {
+ return pButton;
+ }
+ }
+ return null;
+ }
+
private final SelectionListener profileButtonSelectionListener = new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
if (!b.isSelection()) {
makeTableItem(pButton);
} else {
+ if (pButton.getProfile().getEmulatorList().isEmpty()) {
+ return;
+ }
+
+ String profile = pButton.getProfileName();
+ for (TableItem item : table.getSelection()) {
+ VMProperty property = (VMProperty)(item.getData());
+ if (property.getImageProfile().equals(profile)) {
+ table.deselectAll();
+ }
+ }
for (VMProperty property : pButton.getProfile().getEmulatorList()) {
for (TableItem item : table.getItems()) {
if (item.getData() == property) {
}
}
}
-
}
@Override
}
};
+ public void setVMList() {
+ table.removeAll();
+
+ for (ProfileButton pButton : profileButtonList) {
+ if (pButton.getProfile() == null) {
+ continue;
+ }
+ makeTableItem(pButton);
+ }
+
+ table.getColumn(0).setWidth(30);
+ table.getColumn(1).setWidth(100);
+ for (int i = 2; i < titles.length; i++) {
+ table.getColumn(i).pack();
+ }
+ }
+
private void makeTableItem(ProfileButton pButton) {
for (VMProperty property : pButton.getProfile().getEmulatorList()) {
+ addTableItem(pButton, property);
+ }
+ }
+ private void addTableItem (ProfileButton pButton, VMProperty property) {
+ addTableItem(pButton, property, -1);
+ }
+
+ private void addTableItem(VMProperty property) {
+ ProfileButton pButton = findProfileButton(property.getImageProfile());
+ addTableItem(pButton, property, 0);
+ }
+
+ private void addTableItem(ProfileButton pButton, VMProperty property, int index) {
+ if (pButton == null) {
+ return;
+ }
+
+ TableItem item = null;
+ if (index >= 0) {
+ item = new TableItem(table, SWT.NULL, index);
+ } else {
+ item = new TableItem(table, SWT.NULL);
+ }
+
+ item.setImage(1, pButton.getIcon());
+ item.setSelectedImage(1, pButton.getSelectedIcon());
+ if (pButton.getProfileName().equals("wearable")) {
VMPropertyValue value = property.getPropertyValue();
- TableItem item = new TableItem(table, SWT.NULL);
- item.setImage(1, pButton.getIcon());
- item.setSelectedImage(1, pButton.getSelectedIcon());
- if (pButton.getProfileName().equals("wearable")
- && value.baseImage.getSkinShape().equals(SKIN_SHAPE.CIRCLE)) {
+ if (value.baseImage.getSkinShape().equals(SKIN_SHAPE.CIRCLE)) {
item.setSelectedImage(1, ImageResources.ICON_SELECTED_WEARABLE_ROUND.getImage());
}
-
- item.setText(2, value.vmsName);
- item.setText(3, "Samsung Z3");
- item.setText(4, value.baseImage.getPlatformName());
- item.setText(5, value.resolution.getStrTypeValue());
- if (value.fileSharePath == null || value.fileSharePath.isEmpty()) {
- item.setImage(6, ImageResources.ICON_FILE_SHARE_OFF.getImage());
- } else {
- item.setImage(6, ImageResources.ICON_FILE_SHARE_ON.getImage());
- }
- item.setData(property);
}
+
+ setTableItemProperty(item, property);
}
+ private void setTableItemProperty(TableItem item, VMProperty property) {
+ VMPropertyValue value = property.getPropertyValue();
+ if (property.isRunning()) {
+ item.setImage(0, ImageResources.ICON_RUNNING.getImage());
+ }
+ item.setText(2, value.vmsName);
+ item.setText(3, "Samsung Z3");
+ item.setText(4, value.baseImage.getName());
+ item.setText(5, value.resolution.getStrTypeValue());
+ if (value.fileSharePath == null || value.fileSharePath.isEmpty()) {
+ item.setImage(6, ImageResources.ICON_FILE_SHARE_OFF.getImage());
+ } else {
+ item.setImage(6, ImageResources.ICON_FILE_SHARE_ON.getImage());
+ }
+ item.setData(property);
+ }
private void makeVMButton() {
resetButton = new ImageButton(comp, SWT.PUSH);
resetButton.setBackground(null);
VMProperty property = (VMProperty)table.getSelection()[0].getData();
try {
if (MenuHandling.launchEmulator(property)) {
- //
+ reloadProperty();
}
} catch (VMWorkerException e) {
if (e.isNeedRefresh()) {
}
}
- //reloadProperty();
- //redraw();
}
public void exportEmulatorImage() {
VMProperty property = (VMProperty)table.getSelection()[0].getData();
try {
if (MenuHandling.createBaseImage(property)) {
- //reloadProperty();
+ reloadProperty();
}
} catch (VMWorkerException e) {
if (e.isNeedRefresh()) {
try {
if (MenuHandling.resetEmulator(properties)) {
+ reloadProperty();
}
} catch (VMWorkerException e) {
if (e.isNeedRefresh()) {
try {
if (MenuHandling.deleteEmulator(properties)) {
-
+ for (VMProperty property : properties) {
+ Profile profile = property.getPropertyValue().baseImage.getPlatform().getProfileClass();
+ profile.removeEmulator(property);
+ }
+ if (table.getSelectionCount() == table.getItemCount()) {
+ table.removeAll();
+ } else {
+ int[] indices = new int[table.getSelectionCount()];
+ int i = 0;
+ for (TableItem item : table.getSelection()) {
+ indices[i++] = table.indexOf(item);
+ }
+ table.remove(indices);
+ if (table.getItemCount() > 1) {
+ table.setSelection(0);
+ }
+ }
}
} catch (VMWorkerException e) {
if (e.isNeedRefresh()) {
}
}
+ private void reloadProperty() {
+ if (table.getSelectionCount() == 0) {
+ return;
+ }
+
+ for (TableItem item : table.getSelection()) {
+ VMProperty property = (VMProperty) item.getData();
+ property.reloadProperty();
+ setTableItemProperty(item, property);
+ item.redraw();
+ }
+ }
+
private void setLayout() {
// composite is form layout
FormData profileButtonData;
table.setLayoutData(workerButtonData);
}
- private final SelectionListener tableSelectionListener = new SelectionListener() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- int count = table.getSelectionCount();
- if (count == 0) {
+ private void tableSelected() {
+ int count = table.getSelectionCount();
+ if (count == 0) {
+ resetButton.setEnabled(false);
+ exportButton.setEnabled(false);
+ deleteButton.setEnabled(false);
+ modifyButton.setEnabled(false);
+ launchButton.setEnabled(false);
+ } else if (count == 1) {
+ VMProperty prop = (VMProperty)table.getSelection()[0].getData();
+ if (prop.isRunning()) {
resetButton.setEnabled(false);
exportButton.setEnabled(false);
deleteButton.setEnabled(false);
modifyButton.setEnabled(false);
launchButton.setEnabled(false);
- } else if (count == 1) {
- VMProperty prop = (VMProperty)table.getSelection()[0].getData();
+ } else {
+ resetButton.setEnabled(true);
+ exportButton.setEnabled(true);
+ deleteButton.setEnabled(true);
+ modifyButton.setEnabled(true);
+ launchButton.setEnabled(true);
+ }
+ } else {
+ int isRunning = 0;
+ for (TableItem item : table.getSelection()) {
+ VMProperty prop = (VMProperty)item.getData();
if (prop.isRunning()) {
- resetButton.setEnabled(false);
- exportButton.setEnabled(false);
- deleteButton.setEnabled(false);
- modifyButton.setEnabled(false);
- launchButton.setEnabled(false);
- } else {
- resetButton.setEnabled(true);
- exportButton.setEnabled(true);
- deleteButton.setEnabled(true);
- modifyButton.setEnabled(true);
- launchButton.setEnabled(true);
+ isRunning++;
}
+ }
+ if (isRunning == table.getSelectionCount()) {
+ resetButton.setEnabled(false);
+ exportButton.setEnabled(false);
+ deleteButton.setEnabled(false);
+ modifyButton.setEnabled(false);
+ launchButton.setEnabled(false);
} else {
- boolean isRunning = false;
- for (TableItem item : table.getSelection()) {
- VMProperty prop = (VMProperty)item.getData();
- if (prop.isRunning()) {
- isRunning = true;
- } else {
- isRunning = false;
- }
- }
- if (isRunning) {
- resetButton.setEnabled(false);
- exportButton.setEnabled(false);
- deleteButton.setEnabled(false);
- modifyButton.setEnabled(false);
- launchButton.setEnabled(false);
- } else {
- resetButton.setEnabled(true);
- exportButton.setEnabled(false);
- deleteButton.setEnabled(true);
- modifyButton.setEnabled(false);
- launchButton.setEnabled(false);
- }
+ resetButton.setEnabled(true);
+ exportButton.setEnabled(false);
+ deleteButton.setEnabled(true);
+ modifyButton.setEnabled(false);
+ launchButton.setEnabled(false);
}
}
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- };
+ }
}
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.tizen.emulator.manager.renewal.resources.ImageResources;
-import org.tizen.emulator.manager.ui.widgets.ImageButton;
+import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton;
public class VMListTableViewer extends AbstractTableViewer {
Label templateList;
// add linker
templateList = new Label(getTopComp(), SWT.None);
templateList.setText("Templates");
-// templateList.addSelectionListener(new SelectionListener(){
-//
-// @Override
-// public void widgetDefaultSelected(SelectionEvent arg0) {
-// // TODO Auto-generated method stub
-// }
-//
-// @Override
-// public void widgetSelected(SelectionEvent arg0) {
-// // TODO Auto-generated method stub
-// }
-// });
+ // templateList.addSelectionListener(new SelectionListener(){
+ //
+ // @Override
+ // public void widgetDefaultSelected(SelectionEvent arg0) {
+ // // TODO Auto-generated method stub
+ // }
+ //
+ // @Override
+ // public void widgetSelected(SelectionEvent arg0) {
+ // // TODO Auto-generated method stub
+ // }
+ // });
baseImageList = new Label(getTopComp(), SWT.None);
baseImageList.setText("Base Images");
import java.util.ArrayList;
import java.util.List;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
private int[] selection;
TableItem currentItem;
private int itemCount;
+ // if selection count is one, this index is before selected index
private int lastSelectedIndex = -1;
private int focusIndex;
private int topIndex = 0;
checkBox = new CheckBoxButton(tableColumn, SWT.None);
checkBox.setBackground(ColorResources.COLUMN_BG_COLOR);
checkBox.setSelectedBackground(checkBox.getBackground());
-
+
}
addListener();
}
}
+ /**
+ * When widgetSelected is called, the item field of the event object is valid.
+ * If the receiver has the SWT.CHECK style and the check selection changes, the event object detail field contains the value SWT.CHECK.
+ * Widget's DefaultSelected is typically called when an item is double-clicked.
+ * The item field of the event object is valid for default selection, but the detail field is not used.
+ * @param listener
+ */
public void addSelectionListener (SelectionListener listener) {
checkWidget();
if (listener == null) {
private void setTableEmpty() {
items = new TableItem[4];
+ itemCount = 0;
selection = EMPTY_SELECTION;
+ if (isCheck) {
+ checkBox.setSelection(false);
+ checkBox.setEnabled(false);
+ }
}
private static int checkStyle(int style) {
private void removeItem(int index) {
TableItem item = items[index];
if (item != null && !item.isDisposed()) {
+ deselect(index);
item.dispose();
- itemCount--;
- TableItem[] newItems = new TableItem[itemCount];
- System.arraycopy(items, 0, newItems, 0, index);
- System.arraycopy(items, index + 1, newItems, index, itemCount - index);
- items = newItems;
- this.adjustItemIndices(index);
- updateScrollBars(true);
+ if (itemCount == 1) {
+ setTableEmpty();
+ } else {
+ itemCount--;
+ TableItem[] newItems = new TableItem[itemCount];
+ System.arraycopy(items, 0, newItems, 0, index);
+ System.arraycopy(items, index + 1, newItems, index, itemCount - index);
+ items = newItems;
+ this.adjustItemIndices(index);
+ updateScrollBars(true);
+ }
} else {
+ // TODO
destroyItem(null);
}
}
public void removeAll() {
checkWidget();
- while (itemCount > 0) {
- removeItem(0);
+ if (items == null || itemCount == 0) {
+ return;
}
+
+ for (TableItem item : items) {
+ if (item != null) {
+ item.dispose();
+ }
+ }
+
+ setTableEmpty();
}
public void remove(int index) {
}
public void remove(int start, int end) {}
- public void remove(int[] indices) {}
+ public void remove(int[] indices) {
+ checkWidget();
+ if (indices == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+
+ for (int i = 0; i < indices.length; i++) {
+ int index = indices[i];
+ TableItem item = items[index];
+ if (item != null && !item.isDisposed()) {
+ deselect(index);
+ item.dispose();
+ items[index] = null;
+ itemCount--;
+ }
+ }
+ TableItem[] newItems = new TableItem[itemCount];
+ int j = 0;
+ for (TableItem item : items) {
+ if (item != null) {
+ newItems[j++] = item;
+ }
+ }
+ items = newItems;
+ this.adjustItemIndices(0);
+ }
private void removeFromSelection(int index) {
if (index < 0 || index >= itemCount) {
System.arraycopy(selection, i+1, newSelection, i, length - i - 1);
}
selection = newSelection;
+ rearrange(index);
+ showSelection();
break;
}
}
public void deselect(int index) {
checkWidget();
- boolean isNeedReset = selection.length == 1;
removeFromSelection(index);
- if (isNeedReset) {
- lastSelectedIndex = -1;
- this.rearrange(index);
- }
}
public void deselect(int start, int end) {
public void deselectAll() {
checkWidget();
- selection = EMPTY_SELECTION;
+ selection = EMPTY_SELECTION;
+ rearrange(-1);
}
public void select(int index) {
int length = indices.length;
if (length != 0 && ((getStyle() & SWT.SINGLE) == 0
|| length <= 1)) {
-// for (int i = length - 1; i >= 0; --i) {
-// select(indices[i]);
-// }
+ // for (int i = length - 1; i >= 0; --i) {
+ // select(indices[i]);
+ // }
for (int i = 0; i < length; i++) {
select(indices[i]);
}
return result;
}
- private void rearrange(int index) {
- if (lastSelectedIndex == -1) {
- updateScrollBars(true);
- items[index].updateSizeAndLocation(-1);
- for (int i = index + 1; i < items.length; i ++) {
- if (items[i] != null) {
- items[i].updateLocation();
- }
+ private void rearrange(int selectedIndex) {
+ if (isCheck) {
+ if (selection.length != itemCount) {
+ checkBox.setSelection(false);
+ } else {
+ checkBox.setSelection(true);
}
- } else {
- if (lastSelectedIndex > index) {
+ checkBox.redraw();
+ }
+
+ if (selection.length == 1) {
+ int index = selection[0];
+ if (lastSelectedIndex == -1) {
+ updateScrollBars(true);
items[index].updateSizeAndLocation(-1);
- items[lastSelectedIndex].updateSizeAndLocation(-1);
- for (int i = index + 1; i < lastSelectedIndex; i ++) {
+ for (int i = index + 1; i < items.length; i ++) {
if (items[i] != null) {
items[i].updateLocation();
}
}
} else {
+ if (lastSelectedIndex > index) {
+ if (lastSelectedIndex >= itemCount) {
+ lastSelectedIndex = itemCount -1;
+ }
+ items[index].updateSizeAndLocation(-1);
+ items[lastSelectedIndex].updateSizeAndLocation(-1);
+ for (int i = index + 1; i < lastSelectedIndex; i ++) {
+ if (items[i] != null) {
+ items[i].updateLocation();
+ }
+ }
+ } else {
+ items[lastSelectedIndex].updateSizeAndLocation(-1);
+ items[index].updateSizeAndLocation(-1);
+ for (int i = lastSelectedIndex + 1; i < index; i ++) {
+ if (items[i] != null) {
+ items[i].updateLocation();
+ }
+ }
+ }
+ }
+ lastSelectedIndex = index;
+ } else {
+ if (lastSelectedIndex > -1 && lastSelectedIndex < itemCount) {
+ updateScrollBars(true);
items[lastSelectedIndex].updateSizeAndLocation(-1);
- items[index].updateSizeAndLocation(-1);
- for (int i = lastSelectedIndex + 1; i < index; i ++) {
+ for (int i = lastSelectedIndex + 1; i < items.length; i++) {
if (items[i] != null) {
items[i].updateLocation();
}
}
}
+ lastSelectedIndex = -1;
}
- lastSelectedIndex = index;
- }
- private void rearrange() {
- if (lastSelectedIndex > -1) {
- updateScrollBars(true);
- items[lastSelectedIndex].updateSizeAndLocation(-1);
- for (int i = lastSelectedIndex + 1; i < items.length; i++) {
- if (items[i] != null) {
- items[i].updateLocation();
- }
- }
+ showSelection();
+ Event e = new Event();
+ if (selectedIndex > -1) {
+ e.item = items[selectedIndex];
}
- lastSelectedIndex = -1;
+ e.widget = this;
+ notifyListeners(SWT.Selection, e);
}
public void setSelection(int index) {
checkWidget();
+ if (index < 0) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+
deselectAll();
select(index);
if (index < itemCount) {
setFocusIndex(index);
}
+
rearrange(index);
- showSelection();
}
public void setSelection(int start, int end) {
deselectAll();
select(start, end);
if (end >= 0 && start <= end
- && ((getStyle() & SWT.SINGLE) == 0 || start == end)
- && itemCount != 0
- && start < itemCount) {
+ && ((getStyle() & SWT.SINGLE) == 0 || start == end)
+ && itemCount != 0
+ && start < itemCount) {
setFocusIndex(Math.max(0, start));
}
- if (selection.length == 1) {
- rearrange(selection[0]);
- } else if (selection.length >= 2 && lastSelectedIndex > -1) {
- rearrange();
- }
- showSelection();
+
+ rearrange(start);
}
public void setSelection(TableItem item) {
if (item == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
- int index = indexOf(item);
- if (index < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- checkWidget();
- deselectAll();
- select(index);
- setFocusIndex(index);
- rearrange(selection[index]);
- showSelection();
+ setSelection(indexOf(item));
}
public void setSelection(int[] indices ) {
select(indices);
int length = indices.length;
if (length != 0 && ((getStyle() & SWT.SINGLE) == 0
- || length <= 1)) {
+ || length <= 1)) {
setFocusIndex(indices[0]);
}
- if (selection.length == 1) {
- rearrange(selection[0]);
- } else if (selection.length >= 2 && lastSelectedIndex > -1) {
- rearrange();
- }
- showSelection();
+
+ rearrange(indices[0]);
}
public void setSelection(TableItem[] items) {}
}
void _selectAll(boolean select) {
+ if (itemCount == 0) {
+ return;
+ }
+
if (select) {
- deselectAll();
- selectAll();
- rearrange();
+ int[] newSelection = new int[itemCount];
+ for (int i = 0; i < itemCount; i++) {
+ newSelection[i] = i;
+ }
+ setSelection(newSelection);
} else {
deselectAll();
}
-
- showSelection();
- checkBox.redraw();
- if (items.length > 0) {
- Event e = new Event();
- e.item = items[0];
- e.widget = this;
- notifyListeners(SWT.Selection, e);
- }
}
// for table item
void _select(int index) {
- if (selection.length == 1) {
- lastSelectedIndex = selection[0];
- }
+ _select(index, false);
+ }
- if (isCheck && checkBox.isSelection()) {
- checkBox.setSelection(false);
- checkBox.redraw();
- }
+ void _select(int index, boolean isAdd) {
if ((getStyle() & SWT.SINGLE) != 0
- || (!isCtrlKeyOn && !isShiftKeyOn)) {
+ || (!isCtrlKeyOn && !isShiftKeyOn && !isAdd)) {
setSelection(index);
- } else if (isCtrlKeyOn) {
+ } else if (isShiftKeyOn) {
+ if (selection.length > 0) {
+ if (index > (selection[selection.length - 1])) {
+ setSelection(selection[selection.length - 1], index);
+ } else {
+ setSelection(index, selection[selection.length - 1]);
+ }
+ } else {
+ setSelection(index);
+ }
+ } else if (isCtrlKeyOn || isAdd) {
if (this.isSelected(index)) {
if (selection.length == 1) {
this.deselect(index);
setSelection(newSelection);
}
}
- } else if (isShiftKeyOn) {
- if (selection.length > 0) {
- if (index > (selection[selection.length - 1])) {
- setSelection(selection[selection.length - 1], index);
- } else {
- setSelection(index, selection[selection.length - 1]);
- }
- } else {
- setSelection(index);
- }
}
+
Event e = new Event();
e.item = items[index];
e.widget = this;
FormData data = null;
TableColumn c = null;
for( int i = 0; i < seen.length; i++ ) {
- c = columns.get(columnOrder[ i ]);
- data = new FormData();
- if (i == 0) {
- data.top = new FormAttachment(0,0);
- data.left = new FormAttachment(0, 0);
- } else {
- data.top = new FormAttachment(0,0);
- data.left = new FormAttachment(columns.get(columnOrder[ i-1 ]));
- }
- data.width = c.getWidth();
- data.height = 30;
- c.setLayoutData(data);
- c.redraw();
+ c = columns.get(columnOrder[ i ]);
+ data = new FormData();
+ if (i == 0) {
+ data.top = new FormAttachment(0,0);
+ data.left = new FormAttachment(0, 0);
+ } else {
+ data.top = new FormAttachment(0,0);
+ data.left = new FormAttachment(columns.get(columnOrder[ i-1 ]));
}
-
- this.layout(true, true);
+ data.width = c.getWidth();
+ data.height = 30;
+ c.setLayoutData(data);
+ c.redraw();
}
+
+ this.layout(true, true);
}
- }
+ }
+ }
void createColumn(TableColumn column, final int index) {
if (index < 0) {
items[index] = item;
itemCount++;
+ if (itemCount == 1 &&isCheck) {
+ checkBox.setEnabled(true);
+ }
+
adjustItemIndices( index );
// adjust the selection indices
/*
selection[ i ] = selection[ i ] + 1;
}
}
- */
+ */
// advance focusIndex when an item is inserted before the focused item
if( index <= focusIndex ) {
focusIndex++;
}
+
updateScrollBars(true);
}
}
private void adjustItemIndices(int start) {
- for (int i = start; i < itemCount; i++) {
+ int j = 0;
+ int[] newSelection = null;
+ if (selection.length > 0) {
+ newSelection = new int[selection.length];
+ for (int i = 0; i < selection.length; i++) {
+ if (selection[i] < start) {
+ newSelection[j++] = selection[i];
+ }
+ }
+ }
+
+ for (int i = start; i < items.length; i++) {
if (items[i] != null) {
+ if (newSelection != null) {
+ int oldIndex = items[i].getIndex();
+ if (this.isSelected(oldIndex)) {
+ newSelection[j++] = i;
+ }
+ }
items[i].setIndex(i);
}
}
+
+ if (newSelection != null) {
+ setSelection(newSelection);
+ }
}
static final int DEFAULT_WIDTH = 64;
if( ( style & SWT.H_SCROLL ) != 0 ) {
height += getHorizontalBar().getSize().y;
}
- */
+ */
return new Point( width, height );
}
int columnTextHeight = TextSizeUtil.textExtent( headerFont, column.getText(), 0 ).y;
textHeight = Math.max( textHeight, columnTextHeight );
}
- */
+ */
Image image = column.getImage();
int height = image == null ? 0 : image.getBounds().height;
if(height > imageHeight) {
if (getSelectionCount() == 1) {
tableHeight = columnHeight + (itemCount-1) * this.getItemHeight()
- + this.getSelectedItemHeight();
+ + this.getSelectedItemHeight();
} else {
tableHeight = columnHeight + itemCount * this.getItemHeight();
}
int width = Math.max(tableWidth, rect.width);
int height = Math.max(tableHeight, rect.height);
-
+
table.setSize(width, height);
tableColumn.setBounds(0, 0, width, 30);
public void setTopIndex(int index) {
checkWidget();
if (this.topIndex != index
- && index >= 0 && index < itemCount) {
+ && index >= 0 && index < itemCount) {
adjustTopIndex();
if ((getStyle() & SWT.VIRTUAL) != 0) {
redraw();
}
private void adjustTopIndex() {
-// int visibleItemCount = getVisibleItemCount(false);
+ // int visibleItemCount = getVisibleItemCount(false);
int visibleItemCount = 0;
int correction = visibleItemCount == 0 ? 1 : 0;
if (topIndex > itemCount - visibleItemCount - correction) {
int getCheckBoxWidth() {
return checkBoxWidth;
}
-/*
+ /*
public Point getCheckSize() {
return new Point(0, 0);
}
}
return new Point(0, 0);
}
-*/
+ */
public boolean hasColumnImages(int index) {
return columns.get(index).getImage() == null ? false : true;
}
// TODO check style
}
return result;
- */
+ */
return itemHeight;
}
public void showItem(TableItem item) {}
public void showSelection() {
for (TableItem item : items) {
-// if (item != null) {
-// Event event = new Event();
-// event.index = -1;
-// item.notifyListeners(SWT.Resize, event);
-// }
if (item != null) {
item.redraw();
}
leftOffset += width;
}
}
-
+
};
private KeyAdapter controlKeyEvent = new KeyAdapter() {
isCtrlKeyOn = true;
break;
case SWT.SHIFT:
- if (!isCtrlKeyOn) {
- isShiftKeyOn = true;
- }
+ isShiftKeyOn = true;
break;
default:
break;
}
}
newItems[j + 1] = items[i];
-// for (int j = 0; j < i; j++) {
-// if (items[j] == null) {
-// continue;
-// }
-// String value2 = items[j].getText(index);
-// boolean needSort = false;
-// int compare = collator.compare(value1, value2);
-// if (compare > 0 && dir == SWT.UP) {
-// needSort = true;
-// } else if (compare < 0 && dir == SWT.DOWN){
-// needSort = true;
-// }
-
-// if (needSort) {
-// TableItem item = items[i];
-// TableItem[] newItems = new TableItem[itemCount];
-// if (j > 0) {
-// System.arraycopy(items, 0, newItems, 0, j);
-// }
-// System.arraycopy(items, j, newItems,j+1, i - j);
-// System.arraycopy(items, i + 1, newItems, i + 1, itemCount - i - 1);
-// newItems[j] = item;
-// items = newItems;
-// adjustItemIndices(0);
-// }
- }
+ // for (int j = 0; j < i; j++) {
+ // if (items[j] == null) {
+ // continue;
+ // }
+ // String value2 = items[j].getText(index);
+ // boolean needSort = false;
+ // int compare = collator.compare(value1, value2);
+ // if (compare > 0 && dir == SWT.UP) {
+ // needSort = true;
+ // } else if (compare < 0 && dir == SWT.DOWN){
+ // needSort = true;
+ // }
+
+ // if (needSort) {
+ // TableItem item = items[i];
+ // TableItem[] newItems = new TableItem[itemCount];
+ // if (j > 0) {
+ // System.arraycopy(items, 0, newItems, 0, j);
+ // }
+ // System.arraycopy(items, j, newItems,j+1, i - j);
+ // System.arraycopy(items, i + 1, newItems, i + 1, itemCount - i - 1);
+ // newItems[j] = item;
+ // items = newItems;
+ // adjustItemIndices(0);
+ // }
+ }
adjustItemIndices(0);
for (int in = 0; in < selection.length; in++) {
text = "";
//sortButton = new SortButton(this, SWT.NONE);
-// sortButton.addSelectionListener(new SelectionListener() {
-// @Override
-// public void widgetSelected(SelectionEvent se) {
-// Event e = new Event();
-// e.widget = ((SortButton)se.widget).getParent();
-// notifyListeners(SWT.Selection, e);
-// }
-//
-// @Override
-// public void widgetDefaultSelected(SelectionEvent e) {
-// // TODO Auto-generated method stub
-// }
-//
-// });
+ // sortButton.addSelectionListener(new SelectionListener() {
+ // @Override
+ // public void widgetSelected(SelectionEvent se) {
+ // Event e = new Event();
+ // e.widget = ((SortButton)se.widget).getParent();
+ // notifyListeners(SWT.Selection, e);
+ // }
+ //
+ // @Override
+ // public void widgetDefaultSelected(SelectionEvent e) {
+ // // TODO Auto-generated method stub
+ // }
+ //
+ // });
this.setFont(FontResources.COLUMN_FONT);
this.setForeground(ColorResources.COLUMN_FONT_COLOR);
removeListener (SWT.DefaultSelection,listener);
}
+ @Override
public void pack () {
checkWidget();
int w = getPreferredWidth();
}
}
+ @Override
public Table getParent() {
checkWidget();
return parent;
Math.min(color.getGreen() + 15, 255),
Math.min(color.getBlue() + 15, 255));
-// if (sortButton != null) {
-// sortButton.setBackground(color);
-// sortButton.setHoverBackground(selectedBackground);
-// }
+ // if (sortButton != null) {
+ // sortButton.setBackground(color);
+ // sortButton.setHoverBackground(selectedBackground);
+ // }
}
@Override
Point imageEX = new Point(0, 0);
if (image != null) {
imageEX = new Point(image.getImageData().width,
- image.getImageData().height);
+ image.getImageData().height);
}
if (needRedrawingText) {
int textWidth = TextSizeUtil.textExtent(getFont(), drawingText);
switch (getAlignment()) {
case SWT.LEFT:
- imageX += (image != null ? SPACING : 0);
+ imageX += (image != null ? SPACING : 0);
textX += imageX + imageEX.x + SPACING;
break;
case SWT.RIGHT:
imageX += (image != null
- ? rect.width - imageEX.x - SPACING - textWidth - 10
- : rect.width - textWidth - 10);
+ ? rect.width - imageEX.x - SPACING - textWidth - 10
+ : rect.width - textWidth - 10);
textX += imageX + imageEX.x + SPACING;
break;
case SWT.CENTER:
imageX += (image != null
- ? rect.x + ((rect.width - image.getImageData().width - textWidth) / 2)
+ ? rect.x + ((rect.width - image.getImageData().width - textWidth) / 2)
: rect.x + ((rect.width - textWidth) / 2));
textX += imageX + imageEX.x;
break;
@Override
public void mouseDown(MouseEvent e) {
+ parent.setFocus();
if (e.x > (width - RESIZABLE_WIDTH) || width < MIN_WIDTH) {
if (!isResizedState) {
isResizedState = true;
checkBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
- parent._select(index);
+ parent._select(index, true);
}
@Override
}
}
+ @Override
public Table getParent() {
checkWidget();
return parent;
}
+ @Override
public void setBackground(Color color) {
checkWidget();
if (color != null && color.isDisposed()) {
}
}
+ @Override
public Color getBackground() {
checkWidget();
if (!parent.checkData(this, parent.indexOf(this))) {
return getBackground();
}
+ @Override
public void setFont(Font font) {
checkWidget();
if (font != null && font.isDisposed()) {
data.textWidth = -1;
parent.redraw();
}
- }
+ }
}
+ @Override
public Font getFont() {
checkWidget();
if (!parent.checkData(this, parent.indexOf(this))) {
return getFont();
}
+ @Override
public void setForeground(Color color) {
checkWidget();
if (color != null && color.isDisposed()) {
if (color != null && color.isDisposed()) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
-
+
int count = Math.max(1, parent.getColumnCount());
if (index >= 0 && index < count) {
ensureData(index, count);
}
}
+ @Override
public Color getForeground() {
checkWidget();
if (!parent.checkData(this, parent.indexOf(this))) {
return "";
}
+ @Override
public Rectangle getBounds() {
return getBounds(0);
}
updateLocation();
}
+ int getIndex() {
+ return index;
+ }
+
final void shiftData(int index) {
if (dataList != null && dataList.length > index
&& parent.getColumnCount() > 1) {
final int getPackWidth(int index) {
return getImageWidth(index)
- + getSpacing(index)
- + getTextWidth(index, parent.getFont())
- + parent.getCellPadding().width;
+ + getSpacing(index)
+ + getTextWidth(index, parent.getFont())
+ + parent.getCellPadding().width;
}
private int getImageWidth(int index) {
private boolean hasData(int index) {
return dataList != null && index >= 0
- && index < dataList.length && dataList[index] != null;
+ && index < dataList.length && dataList[index] != null;
}
private static Table checkNull (Table control) {
isHoverState = false;
redraw();
break;
- */
+ */
case SWT.MouseDown:
+ parent.setFocus();
parent._select(index);
break;
default:
- break;
+ break;
}
}
-
+
};
private Rectangle clientArea;
isSelected = parent.isSelected(index);
if (isSelected) {
//if (parent.isFocusControl()) {
- gc.setBackground(selectedBackground);
+ gc.setBackground(selectedBackground);
//} else {
// gc.setBackground(focusOutSelectedBackground);
//}
}
if (image != null) {
imageEX = new Point(image.getImageData().width,
- image.getImageData().height);
+ image.getImageData().height);
}
String drawingText = dataList[index].drawingText;
int textWidth = TextSizeUtil.textExtent(getFont(), drawingText);
if (textWidth > (drawingRect.width - imageEX.x - 10)) {
while((textWidth > (drawingRect.width - 10) - TextSizeUtil.OMITLEN)
- && drawingText.length() > 1) {
+ && drawingText.length() > 1) {
drawingText = drawingText.substring(0, drawingText.length() - 1);
textWidth = TextSizeUtil.textExtent(getFont(), drawingText);
}
switch(parent.getColumn(index).getAlignment()) {
case SWT.LEFT:
imageX += (image != null
- ? leftOffset + 5
+ ? leftOffset + 5
: leftOffset + 5);
textX += imageX + imageEX.x + 5;
break;
case SWT.RIGHT:
imageX += (image != null
- ? leftOffset + drawingRect.width - imageEX.x -2 - textWidth - 10
+ ? leftOffset + drawingRect.width - imageEX.x -2 - textWidth - 10
: leftOffset + drawingRect.width - textWidth - 10);
textX += imageX + imageEX.x + 5;
break;
case SWT.CENTER:
imageX += (image != null
- ? leftOffset + (drawingRect.width - image.getImageData().width - textWidth) / 2
+ ? leftOffset + (drawingRect.width - image.getImageData().width - textWidth) / 2
: leftOffset + (drawingRect.width - textWidth) / 2);
textX += imageX + imageEX.x;
break;