From a3fcc9cac1e3564e7a00ee1b3f75ec0900db5f57 Mon Sep 17 00:00:00 2001 From: "jihye424.kim" Date: Fri, 16 Oct 2015 18:52:19 +0900 Subject: [PATCH] MessageBox: add 'DragHandler' to message box - change button to swt button from gray button(custom button) for using focusing and key input('enter' key) - set focus to next table item after to delete device template item Change-Id: I550dfbc479417e4cc7d4fe51bf281025739f98fd Signed-off-by: jihye424.kim --- .../{tableviewer => dialog}/MessageBox.java | 36 +++++++++++++++++----- .../tableviewer/DeviceTemplateTableViewer.java | 11 ++++++- .../ui/renewal/tableviewer/MenuHandling.java | 1 + .../ui/renewal/tableviewer/VMListTable.java | 1 + .../ui/renewal/tableviewer/VMListTableViewer.java | 1 + src/org/tizen/emulator/manager/ui/table/Table.java | 9 +++--- 6 files changed, 46 insertions(+), 13 deletions(-) rename src/org/tizen/emulator/manager/ui/renewal/{tableviewer => dialog}/MessageBox.java (88%) diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MessageBox.java b/src/org/tizen/emulator/manager/ui/renewal/dialog/MessageBox.java similarity index 88% rename from src/org/tizen/emulator/manager/ui/renewal/tableviewer/MessageBox.java rename to src/org/tizen/emulator/manager/ui/renewal/dialog/MessageBox.java index a22e74c..1b3aa41 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MessageBox.java +++ b/src/org/tizen/emulator/manager/ui/renewal/dialog/MessageBox.java @@ -28,20 +28,25 @@ * */ -package org.tizen.emulator.manager.ui.renewal.tableviewer; +package org.tizen.emulator.manager.ui.renewal.dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +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.Label; 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.MainDialog; import org.tizen.emulator.manager.ui.renewal.widgets.CustomScrolledComposite; -import org.tizen.emulator.manager.ui.renewal.widgets.GrayButton; public class MessageBox { private final int MIN_WIDTH = 300; @@ -50,6 +55,9 @@ public class MessageBox { private final int MAX_HEIGHT = 400; private final int TITLE_HEIGHT = 30; + private final int TITLE_MARGIN_TOP = 7; + private final int TITLE_MARGIN_LEFT = 15; + private final int BOTTOM_HEIGHT = 40; private final int BUTTON_WIDTH = 80; private final int BUTTON_HEIGHT = 26; @@ -68,10 +76,12 @@ public class MessageBox { private boolean isOpen = false; private int returnValue = SWT.OK; - private StyledText titleLabel = null; + private Label titleLabel = null; private CustomScrolledComposite scrolledList = null; private StyledText contentsBox = null; + private Composite titleComp = null; + // TODO: Icon SWT.ICON_ERROR ... private static final Shell shell; static { @@ -167,18 +177,28 @@ public class MessageBox { // need dialog size makeButtons(); - titleLabel.setBounds(0, 0, width, TITLE_HEIGHT); + titleComp.setBounds(0, 0, width, TITLE_HEIGHT); scrolledList.setBounds(0, TITLE_HEIGHT, width, height - TITLE_HEIGHT - BOTTOM_HEIGHT); } private void makeTitleLabel() { - titleLabel = new StyledText(dialog, SWT.NONE); + titleComp = new Composite(dialog, SWT.NONE); + titleComp.setBackground(ColorResources.MESSAGE_BOX_TITLE_BG.getColor()); + titleComp.setLayout(new FormLayout()); + + titleLabel = new Label(titleComp, SWT.NONE); titleLabel.setText(this.title); titleLabel.setBackground(ColorResources.MESSAGE_BOX_TITLE_BG.getColor()); titleLabel.setForeground(ColorResources.MESSAGE_BOX_TITLE_FONT.getColor()); titleLabel.setFont(FontResources.MESSAGE_BOX_TITLE.getFont()); - titleLabel.setLeftMargin(SPACING); - titleLabel.setTopMargin(7); + + FormData data = new FormData(); + data.top = new FormAttachment(0, TITLE_MARGIN_TOP); + data.left = new FormAttachment(0, TITLE_MARGIN_LEFT); + titleLabel.setLayoutData(data); + + // make title drag-able + DragHandler.set(dialog, null, titleLabel, titleComp); } private void makeContentsBox() { @@ -202,7 +222,7 @@ public class MessageBox { private int buttonCount = 1; private void makeButton(String text, final int buttonType) { if ((style & buttonType) == buttonType) { - GrayButton button = new GrayButton(dialog, SWT.PUSH); + Button button = new Button(dialog, SWT.PUSH); button.setFont(FontResources.GRAY_BTN_FONT.getFont()); button.setText(text); button.setBackground(null); diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/DeviceTemplateTableViewer.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/DeviceTemplateTableViewer.java index 893604d..3ad7004 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/DeviceTemplateTableViewer.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/DeviceTemplateTableViewer.java @@ -60,6 +60,7 @@ import org.tizen.emulator.manager.renewal.resources.ImageResources; import org.tizen.emulator.manager.renewal.resources.PatchImageResources; import org.tizen.emulator.manager.resources.StringResources; import org.tizen.emulator.manager.ui.renewal.MainDialog; +import org.tizen.emulator.manager.ui.renewal.dialog.MessageBox; import org.tizen.emulator.manager.ui.renewal.dialoghandler.DeviceTemplateDialogHandler; import org.tizen.emulator.manager.ui.renewal.widgets.Hyperlink; import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton; @@ -737,7 +738,15 @@ public class DeviceTemplateTableViewer extends AbstractTableViewer { DeviceTemplate template = (DeviceTemplate)item.getData(); try { template.delete(); - table.remove(table.indexOf(item)); + int index = table.indexOf(item); + table.remove(index); + if (table.getItemCount() > 0) { + if (index == table.getItemCount()) { + table.setSelection(index - 1); + } else { + table.setSelection(index); + } + } } catch (DeviceWorkerException e) { EMLogger.getLogger().warning(e.getMessage()); // open message box diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MenuHandling.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MenuHandling.java index a806d86..b180d7c 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MenuHandling.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MenuHandling.java @@ -37,6 +37,7 @@ import org.tizen.emulator.manager.logging.EMLogger; import org.tizen.emulator.manager.resources.FilePathResources; import org.tizen.emulator.manager.resources.StringResources; import org.tizen.emulator.manager.ui.renewal.MainDialog; +import org.tizen.emulator.manager.ui.renewal.dialog.MessageBox; import org.tizen.emulator.manager.vms.VMProperty; import org.tizen.emulator.manager.vms.helper.VMLauncherException; import org.tizen.emulator.manager.vms.helper.VMWorkerException; 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 b90069d..dc0d457 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java @@ -46,6 +46,7 @@ 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.MainDialog; +import org.tizen.emulator.manager.ui.renewal.dialog.MessageBox; import org.tizen.emulator.manager.ui.renewal.dialoghandler.VMModifyHandler; import org.tizen.emulator.manager.ui.renewal.widgets.CreateVMCombo; import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton; 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 51f50ea..45626d1 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTableViewer.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTableViewer.java @@ -39,6 +39,7 @@ import org.eclipse.swt.widgets.Shell; import org.tizen.emulator.manager.EmulatorManager; import org.tizen.emulator.manager.renewal.resources.ImageResources; import org.tizen.emulator.manager.ui.renewal.MainDialog; +import org.tizen.emulator.manager.ui.renewal.dialog.MessageBox; import org.tizen.emulator.manager.ui.renewal.widgets.Hyperlink; import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton; diff --git a/src/org/tizen/emulator/manager/ui/table/Table.java b/src/org/tizen/emulator/manager/ui/table/Table.java index d63e3c8..387f5a4 100644 --- a/src/org/tizen/emulator/manager/ui/table/Table.java +++ b/src/org/tizen/emulator/manager/ui/table/Table.java @@ -609,6 +609,7 @@ public class Table extends TableScrolledComposite { private void setFocusIndex(int focusIndex) { if (focusIndex >= 0) { this.focusIndex = focusIndex; + items[focusIndex].setFocus(); } } @@ -668,10 +669,10 @@ public class Table extends TableScrolledComposite { } } - Event e = new Event(); - e.item = items[index]; - e.widget = this; - notifyListeners(SWT.Selection, e); +// Event e = new Event(); +// e.item = items[index]; +// e.widget = this; +// notifyListeners(SWT.Selection, e); } public int getItemCount() { -- 2.7.4