From: jihye424.kim Date: Mon, 24 Aug 2015 04:40:28 +0000 (+0900) Subject: VMList View: add vm delete, reset, launch, export as function X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e2e7dd56720e450197ac898fb9049d6797967cb;p=sdk%2Femulator%2Femulator-manager.git VMList View: add vm delete, reset, launch, export as function Change-Id: I0fbe7104e2b390a29ab3d22f70170007d0b50d64 Signed-off-by: jihye424.kim --- diff --git a/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java b/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java index 4d5efbe..1c2959b 100644 --- a/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java +++ b/src/org/tizen/emulator/manager/renewal/resources/ColorResources.java @@ -43,6 +43,8 @@ public enum ColorResources { 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), diff --git a/src/org/tizen/emulator/manager/renewal/resources/FontResources.java b/src/org/tizen/emulator/manager/renewal/resources/FontResources.java index ceabb50..238d6fb 100644 --- a/src/org/tizen/emulator/manager/renewal/resources/FontResources.java +++ b/src/org/tizen/emulator/manager/renewal/resources/FontResources.java @@ -39,54 +39,11 @@ import org.tizen.emulator.manager.EmulatorManager; 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; @@ -172,7 +129,7 @@ public enum FontResources { } 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; diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/AbstractTableViewer.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/AbstractTableViewer.java index 7d97041..26c8183 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/AbstractTableViewer.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/AbstractTableViewer.java @@ -44,11 +44,11 @@ import org.eclipse.swt.widgets.Composite; 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; @@ -102,8 +102,6 @@ public abstract class AbstractTableViewer { makeTopComposite(); makeTableComposite(); - mainComp.setBackground(ColorResources.CHOCOLATE.getColor()); - topComp.setBackground(ColorResources.BLUE.getColor()); tableComp.setBackground(ColorResources.RED.getColor()); settingLayout(); diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MessageBox.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MessageBox.java index 3dae3ce..440b863 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MessageBox.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MessageBox.java @@ -36,15 +36,15 @@ import org.eclipse.swt.events.PaintEvent; 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; @@ -150,6 +150,7 @@ public class MessageBox { makeContentsBox(); // need contentsBox size + dialog.setBackgroundMode(SWT.INHERIT_FORCE); dialog.setBounds(computeDialogBounds()); // need dialog size @@ -166,7 +167,7 @@ public class MessageBox { 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); } @@ -181,7 +182,7 @@ public class MessageBox { 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); @@ -191,9 +192,10 @@ public class MessageBox { 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) { @@ -205,8 +207,8 @@ public class MessageBox { }); 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++; } } diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButtonList.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButtonList.java index 9cad783..847a43f 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButtonList.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButtonList.java @@ -38,7 +38,7 @@ import org.tizen.emulator.manager.platform.Profile; 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; diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java index af567ba..4fd1f10 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java @@ -44,10 +44,10 @@ import org.eclipse.swt.widgets.Listener; 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; @@ -91,22 +91,7 @@ public class VMListTable { 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); @@ -117,7 +102,15 @@ public class VMListTable { } 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() { @@ -138,6 +131,15 @@ public class VMListTable { } } + 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) { @@ -150,6 +152,17 @@ public class VMListTable { 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) { @@ -161,7 +174,6 @@ public class VMListTable { } } } - } @Override @@ -169,30 +181,77 @@ public class VMListTable { } }; + 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); @@ -288,14 +347,12 @@ public class VMListTable { VMProperty property = (VMProperty)table.getSelection()[0].getData(); try { if (MenuHandling.launchEmulator(property)) { - // + reloadProperty(); } } catch (VMWorkerException e) { if (e.isNeedRefresh()) { } } - //reloadProperty(); - //redraw(); } public void exportEmulatorImage() { @@ -306,7 +363,7 @@ public class VMListTable { VMProperty property = (VMProperty)table.getSelection()[0].getData(); try { if (MenuHandling.createBaseImage(property)) { - //reloadProperty(); + reloadProperty(); } } catch (VMWorkerException e) { if (e.isNeedRefresh()) { @@ -340,6 +397,7 @@ public class VMListTable { try { if (MenuHandling.resetEmulator(properties)) { + reloadProperty(); } } catch (VMWorkerException e) { if (e.isNeedRefresh()) { @@ -357,7 +415,23 @@ public class VMListTable { 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()) { @@ -366,6 +440,19 @@ public class VMListTable { } } + 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; @@ -426,59 +513,50 @@ public class VMListTable { 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) { - } - }; + } } diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTableViewer.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTableViewer.java index 66f98fe..50c9538 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTableViewer.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTableViewer.java @@ -36,7 +36,7 @@ import org.eclipse.swt.events.SelectionListener; 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; @@ -71,18 +71,18 @@ public class VMListTableViewer extends AbstractTableViewer { // 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"); diff --git a/src/org/tizen/emulator/manager/ui/table/Table.java b/src/org/tizen/emulator/manager/ui/table/Table.java index fbd1fac..8b7e815 100644 --- a/src/org/tizen/emulator/manager/ui/table/Table.java +++ b/src/org/tizen/emulator/manager/ui/table/Table.java @@ -32,6 +32,7 @@ package org.tizen.emulator.manager.ui.table; 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; @@ -64,6 +65,7 @@ public class Table extends TableScrolledComposite { 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; @@ -115,7 +117,7 @@ public class Table extends TableScrolledComposite { checkBox = new CheckBoxButton(tableColumn, SWT.None); checkBox.setBackground(ColorResources.COLUMN_BG_COLOR); checkBox.setSelectedBackground(checkBox.getBackground()); - + } addListener(); @@ -147,6 +149,13 @@ public class Table extends TableScrolledComposite { } } + /** + * 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) { @@ -168,7 +177,12 @@ public class Table extends TableScrolledComposite { 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) { @@ -209,24 +223,38 @@ public class Table extends TableScrolledComposite { 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) { @@ -238,7 +266,32 @@ public class Table extends TableScrolledComposite { } 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) { @@ -254,6 +307,8 @@ public class Table extends TableScrolledComposite { System.arraycopy(selection, i+1, newSelection, i, length - i - 1); } selection = newSelection; + rearrange(index); + showSelection(); break; } } @@ -261,12 +316,7 @@ public class Table extends TableScrolledComposite { 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) { @@ -285,7 +335,8 @@ public class Table extends TableScrolledComposite { public void deselectAll() { checkWidget(); - selection = EMPTY_SELECTION; + selection = EMPTY_SELECTION; + rearrange(-1); } public void select(int index) { @@ -338,9 +389,9 @@ public class Table extends TableScrolledComposite { 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]); } @@ -411,59 +462,84 @@ public class Table extends TableScrolledComposite { 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) { @@ -471,17 +547,13 @@ public class Table extends TableScrolledComposite { 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) { @@ -489,17 +561,7 @@ public class Table extends TableScrolledComposite { 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 ) { @@ -511,15 +573,11 @@ public class Table extends TableScrolledComposite { 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) {} @@ -531,39 +589,42 @@ public class Table extends TableScrolledComposite { } 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); @@ -587,17 +648,8 @@ public class Table extends TableScrolledComposite { 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; @@ -722,25 +774,25 @@ public class Table extends TableScrolledComposite { 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) { @@ -823,6 +875,10 @@ public class Table extends TableScrolledComposite { items[index] = item; itemCount++; + if (itemCount == 1 &&isCheck) { + checkBox.setEnabled(true); + } + adjustItemIndices( index ); // adjust the selection indices /* @@ -831,11 +887,12 @@ public class Table extends TableScrolledComposite { selection[ i ] = selection[ i ] + 1; } } - */ + */ // advance focusIndex when an item is inserted before the focused item if( index <= focusIndex ) { focusIndex++; } + updateScrollBars(true); } @@ -844,11 +901,32 @@ public class Table extends TableScrolledComposite { } 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; @@ -897,7 +975,7 @@ public class Table extends TableScrolledComposite { if( ( style & SWT.H_SCROLL ) != 0 ) { height += getHorizontalBar().getSize().y; } - */ + */ return new Point( width, height ); } @@ -915,7 +993,7 @@ public class Table extends TableScrolledComposite { 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) { @@ -1009,7 +1087,7 @@ public class Table extends TableScrolledComposite { if (getSelectionCount() == 1) { tableHeight = columnHeight + (itemCount-1) * this.getItemHeight() - + this.getSelectedItemHeight(); + + this.getSelectedItemHeight(); } else { tableHeight = columnHeight + itemCount * this.getItemHeight(); } @@ -1026,7 +1104,7 @@ public class Table extends TableScrolledComposite { int width = Math.max(tableWidth, rect.width); int height = Math.max(tableHeight, rect.height); - + table.setSize(width, height); tableColumn.setBounds(0, 0, width, 30); @@ -1067,7 +1145,7 @@ public class Table extends TableScrolledComposite { 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(); @@ -1080,7 +1158,7 @@ public class Table extends TableScrolledComposite { } 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) { @@ -1101,7 +1179,7 @@ public class Table extends TableScrolledComposite { int getCheckBoxWidth() { return checkBoxWidth; } -/* + /* public Point getCheckSize() { return new Point(0, 0); } @@ -1117,7 +1195,7 @@ public class Table extends TableScrolledComposite { } return new Point(0, 0); } -*/ + */ public boolean hasColumnImages(int index) { return columns.get(index).getImage() == null ? false : true; } @@ -1139,7 +1217,7 @@ public class Table extends TableScrolledComposite { // TODO check style } return result; - */ + */ return itemHeight; } @@ -1183,11 +1261,6 @@ public class Table extends TableScrolledComposite { 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(); } @@ -1268,7 +1341,7 @@ public class Table extends TableScrolledComposite { leftOffset += width; } } - + }; private KeyAdapter controlKeyEvent = new KeyAdapter() { @@ -1279,9 +1352,7 @@ public class Table extends TableScrolledComposite { isCtrlKeyOn = true; break; case SWT.SHIFT: - if (!isCtrlKeyOn) { - isShiftKeyOn = true; - } + isShiftKeyOn = true; break; default: break; @@ -1371,32 +1442,32 @@ public class Table extends TableScrolledComposite { } } 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++) { diff --git a/src/org/tizen/emulator/manager/ui/table/TableColumn.java b/src/org/tizen/emulator/manager/ui/table/TableColumn.java index e1d412c..59d7d17 100644 --- a/src/org/tizen/emulator/manager/ui/table/TableColumn.java +++ b/src/org/tizen/emulator/manager/ui/table/TableColumn.java @@ -131,20 +131,20 @@ public class TableColumn extends Canvas { 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); @@ -181,6 +181,7 @@ public class TableColumn extends Canvas { removeListener (SWT.DefaultSelection,listener); } + @Override public void pack () { checkWidget(); int w = getPreferredWidth(); @@ -189,6 +190,7 @@ public class TableColumn extends Canvas { } } + @Override public Table getParent() { checkWidget(); return parent; @@ -297,10 +299,10 @@ public class TableColumn extends Canvas { 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 @@ -368,7 +370,7 @@ public class TableColumn extends Canvas { Point imageEX = new Point(0, 0); if (image != null) { imageEX = new Point(image.getImageData().width, - image.getImageData().height); + image.getImageData().height); } if (needRedrawingText) { @@ -387,18 +389,18 @@ public class TableColumn extends Canvas { 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; @@ -517,6 +519,7 @@ public class TableColumn extends Canvas { @Override public void mouseDown(MouseEvent e) { + parent.setFocus(); if (e.x > (width - RESIZABLE_WIDTH) || width < MIN_WIDTH) { if (!isResizedState) { isResizedState = true; diff --git a/src/org/tizen/emulator/manager/ui/table/TableItem.java b/src/org/tizen/emulator/manager/ui/table/TableItem.java index b4361d4..0cebb1d 100644 --- a/src/org/tizen/emulator/manager/ui/table/TableItem.java +++ b/src/org/tizen/emulator/manager/ui/table/TableItem.java @@ -119,7 +119,7 @@ public class TableItem extends Canvas { checkBox.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { - parent._select(index); + parent._select(index, true); } @Override @@ -129,11 +129,13 @@ public class TableItem extends Canvas { } } + @Override public Table getParent() { checkWidget(); return parent; } + @Override public void setBackground(Color color) { checkWidget(); if (color != null && color.isDisposed()) { @@ -162,6 +164,7 @@ public class TableItem extends Canvas { } } + @Override public Color getBackground() { checkWidget(); if (!parent.checkData(this, parent.indexOf(this))) { @@ -187,6 +190,7 @@ public class TableItem extends Canvas { return getBackground(); } + @Override public void setFont(Font font) { checkWidget(); if (font != null && font.isDisposed()) { @@ -218,9 +222,10 @@ public class TableItem extends Canvas { data.textWidth = -1; parent.redraw(); } - } + } } + @Override public Font getFont() { checkWidget(); if (!parent.checkData(this, parent.indexOf(this))) { @@ -244,6 +249,7 @@ public class TableItem extends Canvas { return getFont(); } + @Override public void setForeground(Color color) { checkWidget(); if (color != null && color.isDisposed()) { @@ -261,7 +267,7 @@ public class TableItem extends Canvas { 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); @@ -272,6 +278,7 @@ public class TableItem extends Canvas { } } + @Override public Color getForeground() { checkWidget(); if (!parent.checkData(this, parent.indexOf(this))) { @@ -487,6 +494,7 @@ public class TableItem extends Canvas { return ""; } + @Override public Rectangle getBounds() { return getBounds(0); } @@ -607,6 +615,10 @@ public class TableItem extends Canvas { updateLocation(); } + int getIndex() { + return index; + } + final void shiftData(int index) { if (dataList != null && dataList.length > index && parent.getColumnCount() > 1) { @@ -674,9 +686,9 @@ public class TableItem extends Canvas { 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) { @@ -736,7 +748,7 @@ public class TableItem extends Canvas { 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) { @@ -803,15 +815,16 @@ public class TableItem extends Canvas { isHoverState = false; redraw(); break; - */ + */ case SWT.MouseDown: + parent.setFocus(); parent._select(index); break; default: - break; + break; } } - + }; private Rectangle clientArea; @@ -824,7 +837,7 @@ public class TableItem extends Canvas { isSelected = parent.isSelected(index); if (isSelected) { //if (parent.isFocusControl()) { - gc.setBackground(selectedBackground); + gc.setBackground(selectedBackground); //} else { // gc.setBackground(focusOutSelectedBackground); //} @@ -890,7 +903,7 @@ public class TableItem extends Canvas { } if (image != null) { imageEX = new Point(image.getImageData().width, - image.getImageData().height); + image.getImageData().height); } String drawingText = dataList[index].drawingText; @@ -899,7 +912,7 @@ public class TableItem extends Canvas { 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); } @@ -913,19 +926,19 @@ public class TableItem extends Canvas { 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;