--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+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.graphics.Image;
+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.devices.DeviceTemplate;
+import org.tizen.emulator.manager.devices.DeviceTemplateValue;
+import org.tizen.emulator.manager.platform.Profile;
+import org.tizen.emulator.manager.platform.ProfileList;
+import org.tizen.emulator.manager.renewal.resources.ColorResources;
+import org.tizen.emulator.manager.renewal.resources.FontResources;
+import org.tizen.emulator.manager.renewal.resources.ImageResources;
+import org.tizen.emulator.manager.renewal.resources.PatchImageResources;
+import org.tizen.emulator.manager.ui.renewal.MainDialog;
+import org.tizen.emulator.manager.ui.renewal.widgets.Hyperlink;
+import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton;
+import org.tizen.emulator.manager.ui.renewal.widgets.NinePatchResourceInfo;
+import org.tizen.emulator.manager.ui.table.Table;
+import org.tizen.emulator.manager.ui.table.TableColumn;
+import org.tizen.emulator.manager.ui.table.TableItem;
+
+public class DeviceTemplateTableViewer extends AbstractTableViewer {
+ private static final int BACK_BUTTON_WIDTH = 124;
+ private static final int BACK_BUTTON_HEIGHT = 26;
+ private static final int BUTTON_WIDTH = 32;
+ private static final int BUTTON_HEIGHT = 26;
+
+ Hyperlink baseImageList;
+ ImageButton refreshButton;
+
+ private Composite comp;
+ private boolean isTableInitialize = false;
+ private Table table;
+
+ private List<ProfileButton> profileButtonList;
+
+ private ImageButton backButton;
+ private ImageButton createButton;
+ private ImageButton cloneButton;
+ private ImageButton modifyButton;
+ private ImageButton deleteButton;
+
+ public DeviceTemplateTableViewer(Shell shell, String key) {
+ super(shell, key);
+ }
+
+ @Override
+ void setTitleImage() {
+ setTtileBackgroundImage(ImageResources.TEMPLATE_LIST_TITLE_IMAGE.getImage());
+ }
+
+ @Override
+ void setLinkerMenu() {
+ baseImageList = new Hyperlink(getTopComp(), SWT.None);
+ baseImageList.setText("Base Images");
+ baseImageList.addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ if (event.type == SWT.Selection) {
+ if (event.type == SWT.Selection) {
+ MessageBox dialog = new MessageBox(MainDialog.getShell());
+ dialog.setMessage("Click BaseImages menu");
+ dialog.open();
+ }
+ }
+ }
+ });
+ addLinkMenu(baseImageList);
+ }
+
+ @Override
+ void setIconMenu() {
+ refreshButton = new ImageButton(getTopComp(), SWT.PUSH);
+ refreshButton.setImages(ImageResources.BUTTON_REFRESH_NML.getImage(),
+ ImageResources.BUTTON_REFRESH_HOVER.getImage(),
+ ImageResources.BUTTON_REFRESH_HOVER.getImage(),
+ ImageResources.BUTTON_REFRESH_HOVER.getImage());
+
+ refreshButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ // TODO
+ }
+ });
+
+ addIconMenu(refreshButton);
+ }
+
+ @Override
+ void makeTableComposite() {
+ if (table != null) {
+ return;
+ }
+
+ comp = getTableComp();
+
+ makeTable();
+ makeBackButton();
+ makeProfileButton();
+ makeTemplateButton();
+ setLayout();
+ }
+
+ private void makeProfileButton() {
+ profileButtonList = new ArrayList<ProfileButton>();
+ 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 void makeBackButton() {
+ backButton = new ImageButton(comp, SWT.PUSH);
+ Image hover = PatchImageResources.getThreePatchButtonImage(BACK_BUTTON_WIDTH, hoverInfo);
+ Image normal = PatchImageResources.getThreePatchButtonImage(BACK_BUTTON_WIDTH, normalInfo);
+
+ backButton.setText(" Back to VM List");
+ backButton.setFont(FontResources.DEFAULT_FONT_9.getFont());
+ backButton.setFontColor(ColorResources.DEFAULT_FONT.getColor());
+ backButton.setImages(normal, hover, hover, normal);
+ backButton.addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ if (event.type == SWT.Selection) {
+ MainDialog mainDialog = EmulatorManager.getMainDialog();
+ AbstractTableViewer viewer = mainDialog.findViewer("vmList");
+ if (viewer != null) {
+ mainDialog.setStackTop(viewer);
+ }
+ }
+ }
+ });
+ }
+
+ private String[] titles = {"", "Type", "Name", "Resolution", "Display Size", "Ram", "Processor"};
+ private void makeTable() {
+ table = new Table(comp, SWT.BORDER);
+
+ for (String t : titles) {
+ TableColumn column = new TableColumn(table, SWT.None);
+ column.setText(t);
+ column.setAlignment(SWT.CENTER);
+ }
+
+ table.setSelectedItemHeight(table.getItemHeight());
+ table.getColumn(0).setResizable(false);
+ table.getColumn(1).setResizable(false);
+ table.addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(Event e) {
+ if (e.type == SWT.Selection) {
+ tableSelected();
+ }
+ }
+ });
+
+ table.getColumn(2).addListener(SWT.Selection, table.getDefaultSortListener());
+ table.getColumn(3).addListener(SWT.Selection, table.getDefaultSortListener());
+ table.getColumn(4).addListener(SWT.Selection, table.getDefaultSortListener());
+ table.getColumn(5).addListener(SWT.Selection, table.getDefaultSortListener());
+ table.getColumn(6).addListener(SWT.Selection, table.getDefaultSortListener());
+ table.getColumn(1).addListener(SWT.Selection, new Listener() {
+
+ @Override
+ public void handleEvent(Event event) {
+ TableColumn column = (TableColumn)event.widget;
+ // set column
+ table.settingSortColumn(column);
+ // make item compareable list
+ int dir = table.getSortDirection();
+ ItemProfilePair[] pairs = new ItemProfilePair[table.getItemCount()];
+ for (int i = 0; i < table.getItemCount(); i++) {
+ pairs[i] = new ItemProfilePair(table.getItem(i), 1, dir);
+ }
+ column.setTableItemPairs(pairs);
+ // sort table item
+ table.defaultSortTableItem(column);
+ }
+
+ });
+ }
+
+ protected void tableSelected() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ void showTableComposite() {
+ if (!isTableInitialize) {
+ setTemplateList();
+ isTableInitialize = true;
+ }
+
+ }
+
+ private void setTemplateList() {
+ table.removeAll();
+ for (ProfileButton pButton : profileButtonList) {
+ if (pButton.getProfile() == null) {
+ continue;
+ }
+ if (!pButton.getButton().isSelection()) {
+ makeTableItem(pButton);
+ }
+ }
+
+ table.getColumn(0).setWidth(30);
+ table.getColumn(1).setWidth(100);
+ for (int i = 1; i < titles.length; i++) {
+ table.getColumn(i).pack();
+ }
+ }
+
+ private void makeTableItem(ProfileButton pButton) {
+ for (DeviceTemplate template : pButton.getProfile().getTemplateList()) {
+ addTableItem(pButton, template);
+ }
+ }
+
+ private void addTableItem (ProfileButton pButton, DeviceTemplate template) {
+ addTableItem(pButton, template, -1);
+ }
+
+ private void addTableItem(ProfileButton pButton, DeviceTemplate template, 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());
+ setTableItemProperty(item, template);
+ //
+ }
+
+ private void setTableItemProperty(TableItem item, DeviceTemplate template) {
+ DeviceTemplateValue value = template.getValue();
+ item.setText(2, value.getName());
+ item.setText(3, value.getResolution().toString());
+ item.setText(4, String.valueOf(value.getDisplaySize()) + " " + value.getDisplaySizeUnit());
+ item.setText(5, String.valueOf(value.getRamSize()) + " " + value.getRamSizeUnit());
+ item.setText(6, String.valueOf(value.getCpuCount()));
+ item.setData(template);
+ }
+
+ 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().getTemplateList().isEmpty()) {
+ return;
+ }
+
+ String profile = pButton.getProfileName();
+ for (TableItem item : table.getSelection()) {
+ DeviceTemplate template = (DeviceTemplate)(item.getData());
+ if (template.getValue().getProfile().equals(profile)) {
+ table.deselectAll();
+ }
+ }
+ for (DeviceTemplate template : pButton.getProfile().getTemplateList()) {
+ for (TableItem item : table.getItems()) {
+ if (item.getData() == template) {
+ int index = table.indexOf(item);
+ table.remove(index);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ };
+
+ private void makeTemplateButton() {
+ createButton = new ImageButton(comp, SWT.PUSH);
+ createButton.setToolTipText("create device template");
+ createButton.setBackground(null);
+ createButton.setImages(ImageResources.BUTTON_CREATE_NORMAL.getImage(),
+ ImageResources.BUTTON_CREATE_HOVER.getImage(),
+ ImageResources.BUTTON_CREATE_HOVER.getImage(),
+ ImageResources.BUTTON_CREATE_DISABLE.getImage());
+ createButton.addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ if (event.type == SWT.Selection) {
+ // TODO
+ }
+ }
+ });
+
+ cloneButton = new ImageButton(comp, SWT.PUSH);
+ cloneButton.setToolTipText("clone device template");
+ cloneButton.setBackground(null);
+ cloneButton.setImages(ImageResources.BUTTON_CLONE_NORMAL.getImage(),
+ ImageResources.BUTTON_CLONE_HOVER.getImage(),
+ ImageResources.BUTTON_CLONE_HOVER.getImage(),
+ ImageResources.BUTTON_CLONE_DISABLE.getImage());
+ cloneButton.addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ if (event.type == SWT.Selection) {
+ // TODO
+ }
+ }
+ });
+
+ modifyButton = new ImageButton(comp, SWT.PUSH);
+ modifyButton.setToolTipText("modify device template");
+ 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) {
+ // TODO
+ }
+ }
+ });
+
+ deleteButton = new ImageButton(comp, SWT.PUSH);
+ deleteButton.setToolTipText("delete device template");
+ 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) {
+ // TODO
+ }
+ }
+ });
+ }
+
+
+ private void setLayout() {
+ // composite is form layout
+ FormData backButtonData;
+ backButtonData = new FormData();
+ backButtonData.left = new FormAttachment(0, 10);
+ backButtonData.top = new FormAttachment(0, 13);
+ backButtonData.width = BACK_BUTTON_WIDTH;
+ backButtonData.height = BACK_BUTTON_HEIGHT;
+ backButton.setLayoutData(backButtonData);
+
+ 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;
+ deleteButton.setLayoutData(workerButtonData);
+
+ workerButtonData = new FormData();
+ workerButtonData.right = new FormAttachment(deleteButton, -5);
+ 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;
+ cloneButton.setLayoutData(workerButtonData);
+
+ workerButtonData = new FormData();
+ workerButtonData.right = new FormAttachment(cloneButton, -5);
+ workerButtonData.top = new FormAttachment(0, 13);
+ workerButtonData.width = BUTTON_WIDTH;
+ workerButtonData.height = BUTTON_HEIGHT;
+ createButton.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);
+ }
+
+ private NinePatchResourceInfo normalInfo = new NinePatchResourceInfo(ColorResources.TABLE_VIEWER_BG,
+ ColorResources.TABLE_VIEWER_BG,
+ null, //left top
+ ImageResources.BACK_BTN_NORMAL_C, // top -> center
+ null, // right top
+ ImageResources.BACK_BTN_NORMAL_R, // right
+ null, // right bottom
+ null, // bottom
+ null, // left bottom
+ ImageResources.BACK_BTN_NORMAL_L); // left
+
+ private NinePatchResourceInfo hoverInfo = new NinePatchResourceInfo(ColorResources.TABLE_VIEWER_BG,
+ ColorResources.TABLE_VIEWER_BG,
+ null, //left top
+ ImageResources.BACK_BTN_HOVER_C, // top -> center
+ null, // right top
+ ImageResources.BACK_BTN_HOVER_R, // right
+ null, // right bottom
+ null, // bottom
+ null, // left bottom
+ ImageResources.BACK_BTN_HOVER_L); // left
+}