Template: Add text item.
authorminkee.lee <minkee.lee@samsung.com>
Tue, 26 Aug 2014 14:02:22 +0000 (23:02 +0900)
committerminkee.lee <minkee.lee@samsung.com>
Thu, 11 Sep 2014 06:44:15 +0000 (15:44 +0900)
Change-Id: I434a495fc0f6fadfaba644c56d95a5feb9991f4d
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
common-project/src/org/tizen/emulator/manager/ui/detail/item/template/LabelViewItem.java
common-project/src/org/tizen/emulator/manager/ui/detail/item/template/TextSubViewItem.java [new file with mode: 0644]
common-project/src/org/tizen/emulator/manager/ui/detail/item/template/TextViewItem.java

index 2db274e..a93ca66 100644 (file)
@@ -182,6 +182,9 @@ public class LabelViewItem extends AdvancedViewItem{
 
                                } else if (type.equals(ItemType.SPINNER.getName())) {
                                        subItemList.add(new SpinnerSubViewItem(this, compList.get(i++), item));
+
+                               } else if (type.equals(ItemType.TEXT.getName())) {
+                                       subItemList.add(new TextSubViewItem(this, compList.get(i++), item));
                                }
                        }
                }
@@ -203,6 +206,8 @@ public class LabelViewItem extends AdvancedViewItem{
                                count++;
                        } else if (type.equals(ItemType.SPINNER.getName())) {
                                count++;
+                       } else if (type.equals(ItemType.TEXT.getName())) {
+                               count++;
                        }
                }
                return count;
diff --git a/common-project/src/org/tizen/emulator/manager/ui/detail/item/template/TextSubViewItem.java b/common-project/src/org/tizen/emulator/manager/ui/detail/item/template/TextSubViewItem.java
new file mode 100644 (file)
index 0000000..709b6e3
--- /dev/null
@@ -0,0 +1,156 @@
+/* Emulator Manager
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * MunKyu Im <munkyu.im@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@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.detail.item.template;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.tizen.emulator.manager.resources.ColorResources;
+import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.resources.PatchImageResources;
+import org.tizen.emulator.manager.ui.detail.item.ItemChangeState;
+import org.tizen.emulator.manager.ui.widgets.ImageLabel;
+import org.tizen.emulator.manager.vms.VMProperty;
+import org.tizen.emulator.manager.vms.VMPropertyValue;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+
+public class TextSubViewItem extends SubViewItem {
+
+       protected String oldValue;
+       protected String newValue;
+
+       // for modify view
+       protected Text text;
+       protected Image INPUTBOX_ON_IMAGE = null;
+       protected Image INPUTBOX_OFF_IMAGE = null;
+
+       public TextSubViewItem(LabelViewItem parentItem, Composite comp,
+                       Item template) {
+               super(parentItem, comp, template);
+       }
+
+       public void drawModify() {
+               makeCategory();
+
+               if (INPUTBOX_ON_IMAGE == null) {
+                       INPUTBOX_ON_IMAGE = PatchImageResources.getInputBoxON(LABEL_WIDTH);
+               }
+
+               if (INPUTBOX_OFF_IMAGE == null) {
+                       INPUTBOX_OFF_IMAGE = PatchImageResources.getInputBoxOff(LABEL_WIDTH);
+               }
+
+               valueLabel = new ImageLabel(comp, SWT.NONE);
+               valueLabel.setEnableImage(INPUTBOX_ON_IMAGE);
+               valueLabel.setDisableImage(INPUTBOX_OFF_IMAGE);
+               valueLabel.setLayout(new FormLayout());
+
+               FormData data = new FormData();
+               data.left       = new FormAttachment(category, 4);
+               data.top        = new FormAttachment(0, TOP_GAP);
+               data.width      = valueLabel.getSize().x;
+               data.height = valueLabel.getSize().y;
+               valueLabel.setLayoutData(data);
+
+               text = new Text(valueLabel, SWT.NONE);
+               text.setBackground(ColorResources.DETAIL_INPUT_BOX_COLOR.getColor());
+               text.setFont(FontResources.DETAIL_LABEL_FONT.getFont());
+               text.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR.getColor());
+               text.setTextLimit(VMProperty.MAX_NAME_LEN);
+
+               data = new FormData();
+               data.left       = new FormAttachment(0, 5);
+               data.top        = new FormAttachment(0, 2);
+               data.right      = new FormAttachment(100, -5);
+               data.bottom = new FormAttachment(100, -2);
+               text.setLayoutData(data);
+
+               addListener();
+       }
+
+       protected void addListener() {
+               text.addModifyListener(new ModifyListener() {
+                       @Override
+                       public void modifyText(ModifyEvent e) {
+                               newValue = text.getText();
+
+                               if (!parentItem.isCreateMode()) {
+                                       parentItem.getListener().ChangeValue(parentItem.getThis());
+                               }
+                       }
+               });
+
+               text.addKeyListener(new KeyAdapter() {
+                       public void keyPressed(KeyEvent event) {
+                               switch (event.keyCode) {
+                               case SWT.CR:
+                               case SWT.KEYPAD_CR:
+                                       //TODO
+                                       parentItem.getListener().ChangeState(ItemChangeState.CREATE);
+                                       break;
+                               case SWT.ESC:
+                                       parentItem.getListener().ChangeState(ItemChangeState.CANCEL);
+                                       break;
+                               default:
+                                       // TODO
+                                       break;
+                               }
+                       }
+               });
+       }
+
+       @Override
+       public boolean settingDetailItem(VMPropertyValue value) {
+               valueLabel.setText(value.getAdvancedOptionSubValue(parentItem.getName(), name));
+               return true;
+       }
+
+       @Override
+       public void setValue(VMPropertyValue value) {
+               value.setAdvancedOptionSub(parentItem.getName(),  name, newValue);
+       }
+
+       @Override
+       public boolean settingModifyItem(VMPropertyValue value) {
+               newValue = value.getAdvancedOptionSubValue(parentItem.getName(), name);
+               return false;
+       }
+
+}
index 59829db..dbc8b95 100644 (file)
 package org.tizen.emulator.manager.ui.detail.item.template;
 
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.FormAttachment;
 import org.eclipse.swt.layout.FormData;
@@ -41,6 +45,7 @@ import org.tizen.emulator.manager.resources.ColorResources;
 import org.tizen.emulator.manager.resources.FontResources;
 import org.tizen.emulator.manager.resources.PatchImageResources;
 import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem;
+import org.tizen.emulator.manager.ui.detail.item.ItemChangeState;
 import org.tizen.emulator.manager.ui.widgets.ImageLabel;
 import org.tizen.emulator.manager.vms.VMProperty;
 import org.tizen.emulator.manager.vms.VMPropertyValue;
@@ -123,6 +128,7 @@ public class TextViewItem extends AdvancedViewItem{
                data.bottom = new FormAttachment(100, -2);
                text.setLayoutData(data);
 
+               addListener();
        }
 
        @Override
@@ -141,6 +147,38 @@ public class TextViewItem extends AdvancedViewItem{
                }
        }
 
+       public void addListener() {
+               text.addModifyListener(new ModifyListener() {
+                       @Override
+                       public void modifyText(ModifyEvent e) {
+                               newValue = text.getText();
+
+                               if (!isCreateMode()) {
+                                       getListener().ChangeValue(getThis());
+                               }
+                       }
+               });
+
+
+               text.addKeyListener(new KeyAdapter() {
+                       public void keyPressed(KeyEvent event) {
+                               switch (event.keyCode) {
+                               case SWT.CR:
+                               case SWT.KEYPAD_CR:
+                                       //TODO
+                                       getListener().ChangeState(ItemChangeState.CREATE);
+                                       break;
+                               case SWT.ESC:
+                                       getListener().ChangeState(ItemChangeState.CANCEL);
+                                       break;
+                               default:
+                                       // TODO
+                                       break;
+                               }
+                       }
+               });
+       }
+
 
        @Override
        public boolean settingDetailItem(VMPropertyValue value) {