From f841255f74dac91d860ca10d212f6b5fd1a794ac Mon Sep 17 00:00:00 2001 From: "jihye424.kim" Date: Sun, 1 Nov 2015 17:49:54 +0900 Subject: [PATCH] VM List Table: move function buttons to 'VMListTableViewer' - move function buttons to 'VMListTableViewer' from 'VMListTable' - VMListTableViewer -- template list, base image list button -- create, modify, delete, launch button -- profile button - VMListTable -- vm table -- modify, delete, laucnh, reset, export as function Change-Id: I6709eb6aa84bbe101551139ec8f256fb2e6db4f0 Signed-off-by: jihye424.kim --- .../renewal/tableviewer/AbstractTableViewer.java | 9 + .../ui/renewal/tableviewer/VMListTable.java | 705 ++++++++------------- .../ui/renewal/tableviewer/VMListTableViewer.java | 257 +++++++- 3 files changed, 538 insertions(+), 433 deletions(-) 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 c5f5c2d..4e61250 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/AbstractTableViewer.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/AbstractTableViewer.java @@ -60,6 +60,7 @@ public abstract class AbstractTableViewer { private Composite tableComp; private boolean isInitialize = false; + private boolean isRedrawing = true; private static ImageButton infoButton; private List buttonMenuList = new ArrayList(); @@ -87,6 +88,14 @@ public abstract class AbstractTableViewer { return tableComp; } + public boolean isRedrawing() { + return isRedrawing; + } + + public void setRedrawing(boolean isRedrawing) { + this.isRedrawing = isRedrawing; + } + public void initTableViewer() { if (isInitialize) { return; 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 ec19656..f34f346 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java @@ -31,31 +31,23 @@ package org.tizen.emulator.manager.ui.renewal.tableviewer; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Date; -import java.util.List; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.tizen.emulator.manager.devices.DeviceTemplateValue; +import org.tizen.emulator.manager.logging.EMLogger; 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.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.VMModifyHandler; -import org.tizen.emulator.manager.ui.renewal.widgets.CreateVMCombo; -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; @@ -64,26 +56,20 @@ import org.tizen.emulator.manager.vms.VMProperty; import org.tizen.emulator.manager.vms.VMPropertyValue; import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator; import org.tizen.emulator.manager.vms.helper.EmulatorStatusListener; -import org.tizen.emulator.manager.vms.helper.RefreshWorker; import org.tizen.emulator.manager.vms.helper.VMWorkerException; public class VMListTable { - private static final int BUTTON_WIDTH = 32; - private static final int BUTTON_HEIGHT = 26; - - private Composite comp; + private VMListTableViewer viewer; private Table table; - private CreateVMCombo createVM; - - private List profileButtonList; + private VMProperty newEmulator; - private ImageButton deleteButton; - private ImageButton modifyButton; - private ImageButton launchButton; + public VMListTable(VMListTableViewer viewer) { + this.viewer = viewer; + } - public VMListTable(Composite comp) { - this.setComp(comp); + public Table getTable() { + return table; } public void initialize() { @@ -105,23 +91,11 @@ public class VMListTable { }); makeTable(); - makeCreateVMCombo(); - makeProfileButton(); - makeVMButton(); - setLayout(); - } - - public Composite getComp() { - return comp; - } - - public void setComp(Composite comp) { - this.comp = comp; } - String[] titles = {"", "Type", "Name", "Device", "Base Image", "Resolution", "File Sharing"}; + private final String[] titles = {"", "Type", "Name", "Device", "Base Image", "Resolution", "File Sharing"}; private void makeTable() { - table = new Table(comp, SWT.MULTI | SWT.CHECK | SWT.BORDER); + table = new Table(viewer.getTableComp(), SWT.MULTI | SWT.CHECK | SWT.BORDER); for (String t : titles) { TableColumn column = new TableColumn(table, SWT.None); @@ -131,6 +105,7 @@ public class VMListTable { table.getColumn(0).setResizable(false); table.getColumn(1).setResizable(false); + table.addListener(SWT.Selection, new Listener(){ @Override public void handleEvent(Event e) { @@ -140,6 +115,25 @@ public class VMListTable { } }); + table.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent event) { + if (table.getSelectionCount() == 0) { + return; + } + if (event.keyCode != SWT.DEL) { + return; + } + deleteVMList(); + } + }); + + + settingSortingPair(); + makeContextMenu(); + } + + private void settingSortingPair() { table.getColumn(2).addListener(SWT.Selection, table.getDefaultSortListener()); table.getColumn(3).addListener(SWT.Selection, table.getDefaultSortListener()); table.getColumn(4).addListener(SWT.Selection, table.getDefaultSortListener()); @@ -164,267 +158,44 @@ public class VMListTable { } }); - - makeContextMenu(); } - private Menu menu; - private MenuItem modifyMenu; - private MenuItem launchMenu; - private MenuItem deleteMenu; - private MenuItem resetMenu; - private MenuItem exportMenu; - private MenuItem detailMenu; - - private void makeContextMenu() { - menu = new Menu(table); - launchMenu = new MenuItem(menu, SWT.PUSH); - launchMenu.setText("Launch"); - launchMenu.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - if (e.type == SWT.Selection) { - launchEmulator(); - } - } - }); - - modifyMenu = new MenuItem(menu, SWT.PUSH); - modifyMenu.setText("Modify"); - modifyMenu.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - if (e.type == SWT.Selection) { - modifyEmulator(); - } - } - }); - - deleteMenu = new MenuItem(menu, SWT.PUSH); - deleteMenu.setText("Delete\tDelete"); - deleteMenu.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - if (e.type == SWT.Selection) { - deleteVMList(); - } - } - }); - - resetMenu = new MenuItem(menu, SWT.PUSH); - resetMenu.setText("Reset"); - resetMenu.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - if (e.type == SWT.Selection) { - resetVMList(); - } - } - }); - - exportMenu = new MenuItem(menu, SWT.PUSH); - exportMenu.setText("Export as"); - exportMenu.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - if (e.type == SWT.Selection) { - exportEmulatorImage(); - } - } - }); - - new MenuItem(menu, SWT.SEPARATOR); - detailMenu = new MenuItem(menu, SWT.PUSH); - detailMenu.setText("Detail"); - detailMenu.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event e) { - if (e.type == SWT.Selection) { - // TODO - System.out.println("Detail Info"); - } - } - }); - - table.addListener(SWT.MouseDown, new Listener() { - @Override - public void handleEvent(Event event) { - // context menu - int count = table.getSelectionCount(); - if (count < 0) { - return; - } - if (count == 1) { - TableItem item = table.getSelection()[0]; - VMProperty prop = (VMProperty)item.getData(); - if (prop.isRunning()) { - launchMenu.setEnabled(false); - modifyMenu.setEnabled(false); - deleteMenu.setEnabled(false); - resetMenu.setEnabled(false); - exportMenu.setEnabled(false); - detailMenu.setEnabled(true); - } else { - launchMenu.setEnabled(true); - modifyMenu.setEnabled(true); - deleteMenu.setEnabled(true); - resetMenu.setEnabled(true); - exportMenu.setEnabled(true); - detailMenu.setEnabled(true); - } - } else { - boolean available = true; - for (TableItem item : table.getSelection()) { - VMProperty prop = (VMProperty)item.getData(); - if (prop.isRunning()) { - available = false; - break; - } - } - - launchMenu.setEnabled(false); - modifyMenu.setEnabled(false); - deleteMenu.setEnabled(available); - resetMenu.setEnabled(available); - exportMenu.setEnabled(false); - detailMenu.setEnabled(false); - } - - menu.setVisible(true); - } - }); - } - - private void makeCreateVMCombo() { - createVM = new CreateVMCombo(comp, SWT.None); - createVM.addSelectionListener(createVMComboSelectionListener); + // + // drawing emulator list table + // + public void clearVMList(VMProperty prop) { + this.newEmulator = prop; + table.removeAll(); } - private void makeProfileButton() { - profileButtonList = new ArrayList(); - profileButtonList.add(ProfileButtonMaker.getProfileButton("mobile", comp)); - profileButtonList.add(ProfileButtonMaker.getProfileButton("tv", comp)); - profileButtonList.add(ProfileButtonMaker.getProfileButton("wearable", comp)); - - for (Profile profile : ProfileList.getProfileList()) { - for (ProfileButton pButton : profileButtonList) { - if (pButton.getProfileName().equals(profile.getName())) { - pButton.setProfile(profile); - pButton.getButton().setEnabled(true); - pButton.getButton().addSelectionListener(profileButtonSelectionListener); - break; - } + public void makeTableItem(ProfileButton pButton) { + for (VMProperty property : pButton.getProfile().getEmulatorList()) { + if (property == newEmulator) { + addTableItem(pButton, property, 0); + } else { + addTableItem(pButton, property); } } } -// private ProfileButton findProfileButton(String profile) { -// for (ProfileButton pButton : profileButtonList) { -// if (pButton.getProfileName().equals(profile)) { -// return pButton; -// } -// } -// return null; -// } - - private final SelectionListener createVMComboSelectionListener = new SelectionListener() { - - @Override - public void widgetSelected(SelectionEvent e) { - ProfileButton pButton = (ProfileButton)e.data; - MessageBox dialog = new MessageBox(MainDialog.getShell()); - dialog.setMessage("Click create " + pButton.getProfileName() + " VM!!"); - dialog.open(); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - } - - }; - - private final SelectionListener profileButtonSelectionListener = new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent e) { - ImageButton b = (ImageButton)e.widget; - for (ProfileButton pButton : profileButtonList) { - if (pButton.getButton() != b) { - continue; - } - - 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) { - int index = table.indexOf(item); - table.remove(index); - break; - } - } - } - } - } - - tableSelected(); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - } - }; - - public void setVMList() { - table.removeAll(); - createVM.removeAll(); - - for (ProfileButton pButton : profileButtonList) { - if (pButton.getProfile() == null) { - continue; - } - - createVM.add(pButton); - - if (!pButton.getButton().isSelection()) { - makeTableItem(pButton); - } - } - + public void pack() { 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); + if (newEmulator != null) { + table.setSelection(0); } } - private void addTableItem (ProfileButton pButton, VMProperty property) { + public 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) { + public void addTableItem(ProfileButton pButton, VMProperty property, int index) { if (pButton == null) { return; } @@ -530,64 +301,11 @@ public class VMListTable { } } - private void makeVMButton() { - deleteButton = new ImageButton(comp, SWT.PUSH); - deleteButton.setBackground(null); - deleteButton.setImages(ImageResources.BUTTON_DELETE_NORMAL.getImage(), - ImageResources.BUTTON_DELETE_HOVER.getImage(), - ImageResources.BUTTON_DELETE_HOVER.getImage(), - ImageResources.BUTTON_DELETE_DISABLE.getImage()); - deleteButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - if (event.type == SWT.Selection) { - deleteVMList(); - } - } - }); - deleteButton.setToolTipText("delete emulator"); - - modifyButton = new ImageButton(comp, SWT.PUSH); - modifyButton.setBackground(null); - modifyButton.setImages(ImageResources.BUTTON_MODIFY_NORMAL.getImage(), - ImageResources.BUTTON_MODIFY_HOVER.getImage(), - ImageResources.BUTTON_MODIFY_HOVER.getImage(), - ImageResources.BUTTON_MODIFY_DISABLE.getImage()); - modifyButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - if (event.type == SWT.Selection) { - modifyEmulator(); - } - } - }); - modifyButton.setToolTipText("modify emulator"); - - launchButton = new ImageButton(comp, SWT.PUSH); - launchButton.setBackground(null); - launchButton.setImages(ImageResources.BUTTON_RUN_NORMAL.getImage(), - ImageResources.BUTTON_RUN_HOVER.getImage(), - ImageResources.BUTTON_RUN_HOVER.getImage(), - ImageResources.BUTTON_RUN_DISABLE.getImage()); - launchButton.addListener(SWT.Selection, new Listener() { - @Override - public void handleEvent(Event event) { - if (event.type == SWT.Selection) { - launchEmulator(); - } - } - }); - launchButton.setToolTipText("launch emulator"); - - deleteButton.setEnabled(false); - modifyButton.setEnabled(false); - launchButton.setEnabled(false); - } - public void modifyEmulator() { if (table.getSelectionCount() != 1) { return; } + TableItem item = table.getSelection()[0]; VMProperty property = (VMProperty)item.getData(); VMPropertyValue newValue = VMModifyHandler.modify(property); @@ -599,8 +317,13 @@ public class VMListTable { setTableItemProperty(item, property); table.redraw(); } catch (VMWorkerException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (e.isNeedRefresh()) { + viewer.refreshVMPropertyList(); + } + MessageBox.openMessageBox("Failed to modify emulator." + + StringResources.NEW_LINE + + e.getMessage()); + EMLogger.getLogger().warning(e.getMessage()); } } } @@ -617,8 +340,12 @@ public class VMListTable { } } catch (VMWorkerException e) { if (e.isNeedRefresh()) { - refreshVMPropertyList(); + viewer.refreshVMPropertyList(); } + MessageBox.openMessageBox("Failed to launch emulator." + + StringResources.NEW_LINE + + e.getMessage()); + EMLogger.getLogger().warning(e.getMessage()); } } @@ -634,8 +361,12 @@ public class VMListTable { } } catch (VMWorkerException e) { if (e.isNeedRefresh()) { - refreshVMPropertyList(); + viewer.refreshVMPropertyList(); } + MessageBox.openMessageBox("Failed to create new custom base image." + + StringResources.NEW_LINE + + e.getMessage()); + EMLogger.getLogger().warning(e.getMessage()); } } @@ -668,8 +399,12 @@ public class VMListTable { } } catch (VMWorkerException e) { if (e.isNeedRefresh()) { - refreshVMPropertyList(); + viewer.refreshVMPropertyList(); } + MessageBox.openMessageBox("Failed to reset emulator." + + StringResources.NEW_LINE + + e.getMessage()); + EMLogger.getLogger().warning(e.getMessage()); } } @@ -689,24 +424,74 @@ public class VMListTable { 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); + if (table.getSelectionCount() == 1) { + int index = table.getSelectionIndex(); + table.remove(index); + if (table.getItemCount() > 0) { + if (index == table.getItemCount()) { + table.setSelection(index - 1); + } else { + table.setSelection(index); + } + } + } 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); + } } } + tableSelected(); } } catch (VMWorkerException e) { if (e.isNeedRefresh()) { - refreshVMPropertyList(); + viewer.refreshVMPropertyList(); } + MessageBox.openMessageBox("Failed to delete emulator." + + StringResources.NEW_LINE + + e.getMessage()); + EMLogger.getLogger().warning(e.getMessage()); } } + /* + * When click profile button, VMListTableViewer call this function + */ + public void selectProfileButton(ProfileButton pButton) { + if (!pButton.getButton().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) { + int index = table.indexOf(item); + table.remove(index); + break; + } + } + } + } + tableSelected(); + } + + /* + * when emulator has been modified or created or launched + */ private void reloadSelectedProperty() { if (table.getSelectionCount() == 0) { return; @@ -720,15 +505,9 @@ public class VMListTable { } } - private TableItem findTableItem(VMProperty property) { - for (TableItem item : table.getItems()) { - if (item.getData() == property) { - return item; - } - } - return null; - } - + /* + * when emulator has been launched or terminated + */ private void redrawProperty(VMProperty property) { TableItem item = findTableItem(property); if (item == null) { @@ -740,74 +519,31 @@ public class VMListTable { tableSelected(); } - private void setLayout() { - // composite is form layout - FormData createButtonData; - createButtonData = new FormData(); - createButtonData.left = new FormAttachment(0, 10); - createButtonData.top = new FormAttachment(0, 13); - createVM.setLayoutData(createButtonData); - - FormData profileButtonData; - for (int i = 0; i < profileButtonList.size(); i++) { - ProfileButton button = profileButtonList.get(i); - profileButtonData = new FormData(); - if (i == 0) { - profileButtonData.left = new FormAttachment(0, 372); - } else { - profileButtonData.left = new FormAttachment(profileButtonList.get(i-1).getButton(), 2); + private TableItem findTableItem(VMProperty property) { + for (TableItem item : table.getItems()) { + if (item.getData() == property) { + return item; } - profileButtonData.top = new FormAttachment(0, 13); - profileButtonData.width = button.getButton().getSize().x; - profileButtonData.height = button.getButton().getSize().y; - button.getButton().setLayoutData(profileButtonData); } - - FormData workerButtonData = new FormData(); - workerButtonData.right = new FormAttachment(100, -10); - workerButtonData.top = new FormAttachment(0, 13); - workerButtonData.width = BUTTON_WIDTH; - workerButtonData.height = BUTTON_HEIGHT; - launchButton.setLayoutData(workerButtonData); - - workerButtonData = new FormData(); - workerButtonData.right = new FormAttachment(launchButton, -17); - workerButtonData.top = new FormAttachment(0, 13); - workerButtonData.width = BUTTON_WIDTH; - workerButtonData.height = BUTTON_HEIGHT; - modifyButton.setLayoutData(workerButtonData); - - workerButtonData = new FormData(); - workerButtonData.right = new FormAttachment(modifyButton, -5); - workerButtonData.top = new FormAttachment(0, 13); - workerButtonData.width = BUTTON_WIDTH; - workerButtonData.height = BUTTON_HEIGHT; - deleteButton.setLayoutData(workerButtonData); - - workerButtonData = new FormData(); - workerButtonData.top = new FormAttachment(0, 45); - workerButtonData.left = new FormAttachment(0, 10); - workerButtonData.right = new FormAttachment(100, -10); - workerButtonData.bottom = new FormAttachment(100, -10); - table.setLayoutData(workerButtonData); + return null; } - private void tableSelected() { + public void tableSelected() { int count = table.getSelectionCount(); if (count == 0) { - deleteButton.setEnabled(false); - modifyButton.setEnabled(false); - launchButton.setEnabled(false); + viewer.setDeleteButtonEnabled(false); + viewer.setModifyButtonEnabled(false); + viewer.setLaunchButtonEnabled(false); } else if (count == 1) { VMProperty prop = (VMProperty)table.getSelection()[0].getData(); if (prop.isRunning()) { - deleteButton.setEnabled(false); - modifyButton.setEnabled(false); - launchButton.setEnabled(false); + viewer.setDeleteButtonEnabled(false); + viewer.setModifyButtonEnabled(false); + viewer.setLaunchButtonEnabled(false); } else { - deleteButton.setEnabled(true); - modifyButton.setEnabled(true); - launchButton.setEnabled(true); + viewer.setDeleteButtonEnabled(true); + viewer.setModifyButtonEnabled(true); + viewer.setLaunchButtonEnabled(true); } } else { int isRunning = 0; @@ -818,22 +554,141 @@ public class VMListTable { } } if (isRunning == table.getSelectionCount()) { - deleteButton.setEnabled(false); - modifyButton.setEnabled(false); - launchButton.setEnabled(false); + viewer.setDeleteButtonEnabled(false); + viewer.setModifyButtonEnabled(false); + viewer.setLaunchButtonEnabled(false); } else { - deleteButton.setEnabled(true); - modifyButton.setEnabled(false); - launchButton.setEnabled(false); + viewer.setDeleteButtonEnabled(true); + viewer.setModifyButtonEnabled(false); + viewer.setLaunchButtonEnabled(false); } } } - public void refreshVMPropertyList() { - ProfileList.settingVMPropertyList(); - CheckingRunningEmulator.refreshVMPropertyList(); - RefreshWorker.refreshVMConnect(); + private Menu menu; + private MenuItem modifyMenu; + private MenuItem launchMenu; + private MenuItem deleteMenu; + private MenuItem resetMenu; + private MenuItem exportMenu; + private MenuItem detailMenu; + + private void makeContextMenu() { + menu = new Menu(table); + launchMenu = new MenuItem(menu, SWT.PUSH); + launchMenu.setText("Launch"); + launchMenu.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + if (e.type == SWT.Selection) { + launchEmulator(); + } + } + }); + + modifyMenu = new MenuItem(menu, SWT.PUSH); + modifyMenu.setText("Modify"); + modifyMenu.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + if (e.type == SWT.Selection) { + modifyEmulator(); + } + } + }); - setVMList(); + deleteMenu = new MenuItem(menu, SWT.PUSH); + deleteMenu.setText("Delete\tDelete"); + deleteMenu.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + if (e.type == SWT.Selection) { + deleteVMList(); + } + } + }); + + resetMenu = new MenuItem(menu, SWT.PUSH); + resetMenu.setText("Reset"); + resetMenu.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + if (e.type == SWT.Selection) { + resetVMList(); + } + } + }); + + exportMenu = new MenuItem(menu, SWT.PUSH); + exportMenu.setText("Export as"); + exportMenu.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + if (e.type == SWT.Selection) { + exportEmulatorImage(); + } + } + }); + + new MenuItem(menu, SWT.SEPARATOR); + detailMenu = new MenuItem(menu, SWT.PUSH); + detailMenu.setText("Detail"); + detailMenu.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event e) { + if (e.type == SWT.Selection) { + // TODO + System.out.println("Detail Info"); + } + } + }); + + table.addListener(SWT.MouseDown, new Listener() { + @Override + public void handleEvent(Event event) { + // context menu + int count = table.getSelectionCount(); + if (count < 0) { + return; + } + if (count == 1) { + TableItem item = table.getSelection()[0]; + VMProperty prop = (VMProperty)item.getData(); + if (prop.isRunning()) { + launchMenu.setEnabled(false); + modifyMenu.setEnabled(false); + deleteMenu.setEnabled(false); + resetMenu.setEnabled(false); + exportMenu.setEnabled(false); + detailMenu.setEnabled(true); + } else { + launchMenu.setEnabled(true); + modifyMenu.setEnabled(true); + deleteMenu.setEnabled(true); + resetMenu.setEnabled(true); + exportMenu.setEnabled(true); + detailMenu.setEnabled(true); + } + } else { + boolean available = true; + for (TableItem item : table.getSelection()) { + VMProperty prop = (VMProperty)item.getData(); + if (prop.isRunning()) { + available = false; + break; + } + } + + launchMenu.setEnabled(false); + modifyMenu.setEnabled(false); + deleteMenu.setEnabled(available); + resetMenu.setEnabled(available); + exportMenu.setEnabled(false); + detailMenu.setEnabled(false); + } + + menu.setVisible(true); + } + }); } } 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 c7fe3b8..1a5130c 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTableViewer.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTableViewer.java @@ -30,39 +30,97 @@ package org.tizen.emulator.manager.ui.renewal.tableviewer; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.tizen.emulator.manager.EmulatorManager; +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.widgets.CreateVMCombo; import org.tizen.emulator.manager.ui.renewal.widgets.Hyperlink; import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton; +import org.tizen.emulator.manager.vms.VMProperty; +import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator; +import org.tizen.emulator.manager.vms.helper.RefreshWorker; public class VMListTableViewer extends AbstractTableViewer { - Hyperlink templateList; - Hyperlink baseImageList; - ImageButton refreshButton; + private static final int BUTTON_WIDTH = 32; + private static final int BUTTON_HEIGHT = 26; + + private Hyperlink templateList; + private Hyperlink baseImageList; + private ImageButton refreshButton; + + private CreateVMCombo createVMCombo; + + private List profileButtonList; + + private ImageButton deleteButton; + private ImageButton modifyButton; + private ImageButton launchButton; + + private Composite comp; + private VMListTable table; + private VMProperty newVM; - VMListTable table; public VMListTableViewer(Shell shell, String key) { super(shell, key); } @Override void makeTableComposite() { - // TODO: create new vm button + comp = getTableComp(); + + makeCreateVMCombo(); + makeProfileButton(); + makeVMButton(); - table = new VMListTable(getTableComp()); + table = new VMListTable(this); table.initialize(); + + setLayout(); } @Override void showTableComposite() { - table.setVMList(); + if (isRedrawing()) { + createVMCombo.removeAll(); + + for (ProfileButton pButton : profileButtonList) { + createVMCombo.add(pButton); + } + + redrawingTable(newVM); + } + + setRedrawing(false); + } + + public void redrawingTable(VMProperty newVM) { + table.clearVMList(newVM); + + for (ProfileButton pButton : profileButtonList) { + if (pButton.getProfile() == null) { + continue; + } + + if (!pButton.getButton().isSelection()) { + table.makeTableItem(pButton); + } + } + + table.pack(); } @Override @@ -132,10 +190,193 @@ public class VMListTableViewer extends AbstractTableViewer { @Override public void widgetSelected(SelectionEvent arg0) { - table.refreshVMPropertyList(); + refreshVMPropertyList(); } }); addIconMenu(refreshButton); } + + // reloading emulator list from data directory + public void refreshVMPropertyList() { + ProfileList.settingVMPropertyList(); + CheckingRunningEmulator.refreshVMPropertyList(); + RefreshWorker.refreshVMConnect(); + + redrawingTable(null); + } + + public void setCreatedEmulator(VMProperty prop) { + newVM = prop; + } + + public void setDeleteButtonEnabled(boolean enable) { + deleteButton.setEnabled(enable); + } + + public void setModifyButtonEnabled(boolean enable) { + modifyButton.setEnabled(enable); + } + + public void setLaunchButtonEnabled(boolean enable) { + launchButton.setEnabled(enable); + } + + private void makeCreateVMCombo() { + createVMCombo = new CreateVMCombo(comp, SWT.None); + createVMCombo.addSelectionListener(createVMComboSelectionListener); + } + + private void makeProfileButton() { + profileButtonList = new ArrayList(); + profileButtonList.add(ProfileButtonMaker.getProfileButton("mobile", comp)); + profileButtonList.add(ProfileButtonMaker.getProfileButton("tv", comp)); + profileButtonList.add(ProfileButtonMaker.getProfileButton("wearable", comp)); + + for (Profile profile : ProfileList.getProfileList()) { + for (ProfileButton pButton : profileButtonList) { + if (pButton.getProfileName().equals(profile.getName())) { + pButton.setProfile(profile); + pButton.getButton().setEnabled(true); + pButton.getButton().addSelectionListener(profileButtonSelectionListener); + break; + } + } + } + } + + private final SelectionListener createVMComboSelectionListener = new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + //TODO + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + + private final SelectionListener profileButtonSelectionListener = new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + ImageButton b = (ImageButton)e.widget; + for (ProfileButton pButton : profileButtonList) { + if (pButton.getButton() == b) { + table.selectProfileButton(pButton); + break; + } + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }; + + private void makeVMButton() { + deleteButton = new ImageButton(comp, SWT.PUSH); + deleteButton.setBackground(null); + deleteButton.setImages(ImageResources.BUTTON_DELETE_NORMAL.getImage(), + ImageResources.BUTTON_DELETE_HOVER.getImage(), + ImageResources.BUTTON_DELETE_HOVER.getImage(), + ImageResources.BUTTON_DELETE_DISABLE.getImage()); + deleteButton.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event event) { + if (event.type == SWT.Selection) { + table.deleteVMList(); + } + } + }); + deleteButton.setToolTipText("delete emulator"); + + modifyButton = new ImageButton(comp, SWT.PUSH); + modifyButton.setBackground(null); + modifyButton.setImages(ImageResources.BUTTON_MODIFY_NORMAL.getImage(), + ImageResources.BUTTON_MODIFY_HOVER.getImage(), + ImageResources.BUTTON_MODIFY_HOVER.getImage(), + ImageResources.BUTTON_MODIFY_DISABLE.getImage()); + modifyButton.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event event) { + if (event.type == SWT.Selection) { + table.modifyEmulator(); + } + } + }); + modifyButton.setToolTipText("modify emulator"); + + launchButton = new ImageButton(comp, SWT.PUSH); + launchButton.setBackground(null); + launchButton.setImages(ImageResources.BUTTON_RUN_NORMAL.getImage(), + ImageResources.BUTTON_RUN_HOVER.getImage(), + ImageResources.BUTTON_RUN_HOVER.getImage(), + ImageResources.BUTTON_RUN_DISABLE.getImage()); + launchButton.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event event) { + if (event.type == SWT.Selection) { + table.launchEmulator(); + } + } + }); + launchButton.setToolTipText("launch emulator"); + + deleteButton.setEnabled(false); + modifyButton.setEnabled(false); + launchButton.setEnabled(false); + } + + private void setLayout() { + // composite is form layout + FormData createButtonData; + createButtonData = new FormData(); + createButtonData.left = new FormAttachment(0, 10); + createButtonData.top = new FormAttachment(0, 13); + createVMCombo.setLayoutData(createButtonData); + + FormData profileButtonData; + for (int i = 0; i < profileButtonList.size(); i++) { + ProfileButton button = profileButtonList.get(i); + profileButtonData = new FormData(); + if (i == 0) { + profileButtonData.left = new FormAttachment(0, 372); + } else { + profileButtonData.left = new FormAttachment(profileButtonList.get(i-1).getButton(), 2); + } + profileButtonData.top = new FormAttachment(0, 13); + profileButtonData.width = button.getButton().getSize().x; + profileButtonData.height = button.getButton().getSize().y; + button.getButton().setLayoutData(profileButtonData); + } + + FormData workerButtonData = new FormData(); + workerButtonData.right = new FormAttachment(100, -10); + workerButtonData.top = new FormAttachment(0, 13); + workerButtonData.width = BUTTON_WIDTH; + workerButtonData.height = BUTTON_HEIGHT; + launchButton.setLayoutData(workerButtonData); + + workerButtonData = new FormData(); + workerButtonData.right = new FormAttachment(launchButton, -17); + workerButtonData.top = new FormAttachment(0, 13); + workerButtonData.width = BUTTON_WIDTH; + workerButtonData.height = BUTTON_HEIGHT; + modifyButton.setLayoutData(workerButtonData); + + workerButtonData = new FormData(); + workerButtonData.right = new FormAttachment(modifyButton, -5); + workerButtonData.top = new FormAttachment(0, 13); + workerButtonData.width = BUTTON_WIDTH; + workerButtonData.height = BUTTON_HEIGHT; + deleteButton.setLayoutData(workerButtonData); + + workerButtonData = new FormData(); + workerButtonData.top = new FormAttachment(0, 45); + workerButtonData.left = new FormAttachment(0, 10); + workerButtonData.right = new FormAttachment(100, -10); + workerButtonData.bottom = new FormAttachment(100, -10); + table.getTable().setLayoutData(workerButtonData); + } } -- 2.7.4