*
*/
-
package org.tizen.webuibuilder.ui.editor.viewer;
import java.util.List;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.requests.LocationRequest;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseEvent;
-import org.tizen.webuibuilder.bridge.DesignerGoingBridge.WidgetPosition;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
import org.tizen.webuibuilder.gef.editparts.DesignerEditPart;
-import org.tizen.webuibuilder.model.Part;
+import org.tizen.webuibuilder.gef.editparts.HoverViewerEditPart;
import org.tizen.webuibuilder.ui.quickstyle.QuickStyleConstants;
-import org.tizen.webuibuilder.ui.views.properties.HTMLBlockPropertyModifier;
-
+import org.tizen.webuibuilder.ui.selector.CSSSelectorDialog;
public class DesignerEventDelegator extends HoverBrowserEventDelegator {
- private DesignerBrowserViewer designEditPartViewer;
-
- public DesignerEventDelegator(DesignerBrowserViewer viewer) {
- super(viewer);
- designEditPartViewer = viewer;
- }
-
- @Override
- public void mouseDoubleClick(MouseEvent e) {
- @SuppressWarnings("unchecked")
- List<DesignerEditPart> selectionParts = designEditPartViewer.getSelectedEditParts();
- if (selectionParts == null || selectionParts.isEmpty()) {
- return;
- } // else : keep going
- DesignerEditPart selectionDesignerPart = selectionParts.get(0);
- Part model = (Part) selectionDesignerPart.getModel();
- String partId = selectionDesignerPart.getId();
- // DescriptorManager descriptorManager =
- // (DescriptorManager)selectionDesignerPart.getViewer().getProperty("DescriptorManager");
- // TODO : apply to all widgets
- if (model.getDescriptorId().equals("html.htmlblock")) {
- WidgetPosition pos = designEditPartViewer.getBrowser().getWidgetPosition(partId);
- if (pos == null) {
- return;
- } // else : keep going
- if (pos.contains(e.x, e.y)) {
- // TODO : do default action from part descriptor
- HTMLBlockPropertyModifier.getInstance(model).openEditor(model);
- } // else : do nothing
- }
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- if (e.keyCode == SWT.SPACE) {
- @SuppressWarnings("unchecked")
- List<DesignerEditPart> selectionParts = designEditPartViewer.getSelectedEditParts();
- if (selectionParts == null || selectionParts.isEmpty()) {
- return;
- } // else : keep going
- DesignerEditPart selectionDesignerPart = selectionParts.get(0);
- Rectangle rect = selectionDesignerPart.getFigure().getBounds();
- Point pt = new Point(rect.x, rect.y);
- LocationRequest request = new LocationRequest(QuickStyleConstants.REQ_LOCATION);
- request.setLocation(pt);
- selectionDesignerPart.showTargetFeedback(request);
- }
- }
-
- private DesignerEditPart selectedEditPart = null;
- private boolean openFlag = false;
-
- @Override
- public void mouseUp(MouseEvent e) {
- super.mouseUp(e);
- if ((e.stateMask & SWT.BUTTON1) != 0) {
- @SuppressWarnings("unchecked")
- List<DesignerEditPart> selectionParts = designEditPartViewer.getSelectedEditParts();
- if (selectionParts == null || selectionParts.isEmpty()) {
- return;
- } // else : keep going
-
- DesignerEditPart selectionDesignerPart = selectionParts.get(0);
-
- if (selectedEditPart != selectionDesignerPart) {
- selectedEditPart = selectionDesignerPart;
- openFlag = false;
- } else if (!openFlag) {
- openFlag = true;
- Point pt = new Point(e.x, e.y);
- LocationRequest request = new LocationRequest(QuickStyleConstants.REQ_LOCATION);
- request.setLocation(pt);
- selectionDesignerPart.showTargetFeedback(request);
- }
- }
- }
+ private DesignerBrowserViewer designEditPartViewer;
+
+ public DesignerEventDelegator(DesignerBrowserViewer viewer) {
+ super(viewer);
+ designEditPartViewer = viewer;
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ System.out.println("test double click!");
+ @SuppressWarnings("unchecked")
+ List<DesignerEditPart> selectionParts = designEditPartViewer
+ .getSelectedEditParts();
+ if (selectionParts == null || selectionParts.isEmpty()) {
+ return;
+ } // else : keep going
+ DesignerEditPart selectionDesignerPart = selectionParts.get(0);
+ // Part model = (Part) selectionDesignerPart.getModel();
+ // String partId = selectionDesignerPart.getId();
+ Control control = designEditPartViewer.getControl();
+ HoverViewerEditPart hpart = designEditPartViewer.getCurrentPage();
+ EditPartViewer viewer = hpart.getViewer();
+ Control control2 = viewer.getControl();
+ Rectangle rect = selectionDesignerPart.getFigure().getBounds();
+ org.eclipse.swt.graphics.Point p = control.toDisplay(rect.x, rect.y);
+
+ int x = p.x + rect.width, y = p.y;
+
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getShell();
+ CSSSelectorDialog selector = new CSSSelectorDialog(shell);
+ selector.setPosition(x, y);
+ String obj = (String)selector.open();
+ System.out.println(obj);
+
+ // DescriptorManager descriptorManager =
+ // (DescriptorManager)selectionDesignerPart.getViewer().getProperty("DescriptorManager");
+ // TODO : apply to all widgets
+ // if (model.getDescriptorId().equals("html.htmlblock")) {
+ // WidgetPosition pos =
+ // designEditPartViewer.getBrowser().getWidgetPosition(partId);
+ // if (pos == null) {
+ // return;
+ // } // else : keep going
+ // if (pos.contains(e.x, e.y)) {
+ // // TODO : do default action from part descriptor
+ // HTMLBlockPropertyModifier.getInstance(model).openEditor(model);
+ // } // else : do nothing
+ // }
+
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ if (e.keyCode == SWT.SPACE) {
+ @SuppressWarnings("unchecked")
+ List<DesignerEditPart> selectionParts = designEditPartViewer
+ .getSelectedEditParts();
+ if (selectionParts == null || selectionParts.isEmpty()) {
+ return;
+ } // else : keep going
+ DesignerEditPart selectionDesignerPart = selectionParts.get(0);
+ Rectangle rect = selectionDesignerPart.getFigure().getBounds();
+ Point pt = new Point(rect.x, rect.y);
+ LocationRequest request = new LocationRequest(
+ QuickStyleConstants.REQ_LOCATION);
+ request.setLocation(pt);
+ selectionDesignerPart.showTargetFeedback(request);
+ }
+ }
+
+ private DesignerEditPart selectedEditPart = null;
+ private boolean openFlag = false;
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ super.mouseUp(e);
+ if ((e.stateMask & SWT.BUTTON1) != 0) {
+ @SuppressWarnings("unchecked")
+ List<DesignerEditPart> selectionParts = designEditPartViewer
+ .getSelectedEditParts();
+ if (selectionParts == null || selectionParts.isEmpty()) {
+ return;
+ } // else : keep going
+
+ DesignerEditPart selectionDesignerPart = selectionParts.get(0);
+
+ if (selectedEditPart != selectionDesignerPart) {
+ selectedEditPart = selectionDesignerPart;
+ openFlag = false;
+ } else if (!openFlag) {
+ openFlag = true;
+ Point pt = new Point(e.x, e.y);
+ LocationRequest request = new LocationRequest(
+ QuickStyleConstants.REQ_LOCATION);
+ request.setLocation(pt);
+ selectionDesignerPart.showTargetFeedback(request);
+ }
+ }
+ }
}
\ No newline at end of file
--- /dev/null
+package org.tizen.webuibuilder.ui.selector;
+
+import org.eclipse.jface.window.Window.IExceptionHandler;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class BaseMessageBox {
+ protected Shell shell = null;
+ protected Object result = null;
+ protected boolean initSuccess = false;
+ protected boolean block = false;
+ protected Shell parentShell = null;
+
+ protected static IExceptionHandler exceptionHandler = new DefaultExceptionHandler();
+
+ public BaseMessageBox(Shell parentShell) {
+ this.parentShell = parentShell;
+ shell = new Shell(parentShell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+ }
+
+ public Object open() {
+ block = true;
+ initSuccess = run();
+ if (initSuccess) {
+ shell.open();
+ if (block) {
+ runEventLoop(shell);
+ }
+ }
+ shell.dispose();
+ closeAction();
+ return result;
+ }
+
+ protected boolean run() {
+ return true;
+ }
+
+ protected Object closeAction() {
+ return result;
+ }
+
+ protected void runEventLoop(Shell loopShell) {
+
+ // Use the display provided by the shell if possible
+ Display display;
+ if (shell == null) {
+ display = Display.getCurrent();
+ } else {
+ display = loopShell.getDisplay();
+ }
+
+ while (loopShell != null && !loopShell.isDisposed()) {
+ try {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ } catch (SWTException e) {
+ exceptionHandler.handleException(e);
+ }
+ }
+ if (!display.isDisposed()) {
+ display.update();
+ }
+ }
+
+ private static class DefaultExceptionHandler implements IExceptionHandler {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.window.Window.IExceptionHandler#handleException
+ * (java.lang.Throwable)
+ */
+ public void handleException(Throwable t) {
+ if (t instanceof ThreadDeath) {
+ // Don't catch ThreadDeath as this is a normal occurrence when
+ // the thread dies
+ throw (ThreadDeath) t;
+ }
+ // Try to keep running.
+ t.printStackTrace();
+ }
+ }
+}
--- /dev/null
+package org.tizen.webuibuilder.ui.selector;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StackLayout;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+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.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.tizen.webuibuilder.ui.selector.BaseMessageBox;
+import org.tizen.webuibuilder.ui.selector.SelectorElement;
+
+public class CSSSelectorDialog extends BaseMessageBox {
+
+ private Label label = null;
+ private Button domRadio = null;
+ private Button classRadio = null;
+ private Combo combo = null;
+ private Tree tree = null;
+ private Table table = null;
+ private Composite bodyComposite = null;
+
+ private Button okButton = null;
+ private Button cancelButton = null;
+
+ public CSSSelectorDialog(Shell parentShell) {
+ super(parentShell);
+ }
+
+ @Override
+ protected boolean run() {
+ shell.setLayout(new FormLayout());
+ shell.setSize(340, 365);
+
+ label = new Label(shell, SWT.TRANSPARENT);
+ FormData data = new FormData();
+ data.top = new FormAttachment(0, 11);
+ data.left = new FormAttachment(0, 12);
+ data.height = 15;
+ data.width = 150;
+ label.setLayoutData(data);
+ label.setText("ID : ");
+
+ domRadio = new Button(shell, SWT.RADIO);
+ data = new FormData();
+ data.top = new FormAttachment(label, 10);
+ data.left = new FormAttachment(0, 9);
+ data.height = 20;
+ data.width = 80;
+ domRadio.setLayoutData(data);
+ domRadio.setText("DOM");
+ domRadio.setSelection(true);
+ domRadio.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ StackLayout layout = (StackLayout) bodyComposite.getLayout();
+ layout.topControl = tree;
+ bodyComposite.layout();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+
+ classRadio = new Button(shell, SWT.RADIO);
+ data = new FormData();
+ data.top = new FormAttachment(label, 10);
+ data.left = new FormAttachment(domRadio, 9);
+ data.height = 20;
+ data.width = 80;
+ classRadio.setLayoutData(data);
+ classRadio.setText("Class");
+ classRadio.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ StackLayout layout = (StackLayout) bodyComposite.getLayout();
+ layout.topControl = table;
+ bodyComposite.layout();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+
+ combo = new Combo(shell, SWT.READ_ONLY);
+ data = new FormData();
+ data.top = new FormAttachment(label, 10);
+ data.left = new FormAttachment(classRadio, 20);
+ data.height = 20;
+ data.width = 128;
+ combo.setLayoutData(data);
+ combo.add("None");
+ combo.add("test1");
+ combo.select(0);
+
+ bodyComposite = new Composite(shell, SWT.SINGLE);
+ bodyComposite.setLayout(new StackLayout());
+ data = new FormData();
+ data.top = new FormAttachment(domRadio, 10);
+ data.left = new FormAttachment(0, 9);
+ data.height = 200;
+ data.width = 300;
+ bodyComposite.setLayoutData(data);
+
+ tree = new Tree(bodyComposite, SWT.SINGLE | SWT.BORDER);
+ tree.setHeaderVisible(true);
+ tree.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+
+ tree.addMouseListener(new MouseListener() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ result = updateTree();
+ shell.dispose();
+ }
+ });
+
+ table = new Table(bodyComposite, SWT.SINGLE | SWT.BORDER);
+ table.setHeaderVisible(false);
+ table.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+
+ table.addMouseListener(new MouseListener() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ result = updateTable();
+ shell.dispose();
+ }
+ });
+
+ ((StackLayout) (bodyComposite.getLayout())).topControl = tree;
+
+ cancelButton = new Button(shell, SWT.PUSH);
+ data = new FormData();
+ data.top = new FormAttachment(bodyComposite, 20);
+ data.right = new FormAttachment(100, -9);
+ data.height = 25;
+ data.width = 80;
+ cancelButton.setLayoutData(data);
+ cancelButton.setText("Cancel");
+ cancelButton.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ shell.dispose();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+
+ okButton = new Button(shell, SWT.PUSH);
+ data = new FormData();
+ data.top = new FormAttachment(bodyComposite, 20);
+ data.right = new FormAttachment(cancelButton, -9);
+ data.height = 25;
+ data.width = 80;
+ okButton.setLayoutData(data);
+ okButton.setText("Ok");
+
+ okButton.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ // DesignerGoingBridge dtr = new DesignerGoingBridge(
+ // new ImageBufferedBrowser(false, false));
+ // dtr.getElementDom();
+
+ result = updateTree();
+ shell.dispose();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+
+ createTree();
+ createTable();
+ return true;
+ }
+
+ public void setPosition(int x, int y) {
+ shell.setLocation(x, y);
+ }
+
+ protected void createTree() {
+
+ // create element from JSON format
+ // example
+ SelectorElement se1 = new SelectorElement(null, "span", "ui-btn-inner",
+ null);
+ SelectorElement se2 = new SelectorElement(null, "span", "ui-btn-text",
+ se1);
+
+ TreeColumn tc = new TreeColumn(tree, SWT.NONE);
+ tc.setText("button1");
+ tc.setWidth(100);
+
+ TreeItem tr2 = new TreeItem(tree, SWT.NONE);
+ tr2.setText(se1.getTagName());
+ tr2.setData(se1);
+
+ TreeItem tr3 = new TreeItem(tr2, SWT.NONE);
+ tr3.setText(se2.getTagName());
+ tr3.setData(se2);
+ }
+
+ protected void createTable() {
+ SelectorElement se1 = new SelectorElement(null, "span", "ui-btn-inner",
+ null);
+ SelectorElement se2 = new SelectorElement(null, "span", "ui-btn-text",
+ se1);
+
+ TableColumn tc = new TableColumn(table, SWT.NONE);
+ tc.setText("button1");
+ tc.setWidth(100);
+
+ TableItem tr2 = new TableItem(table, SWT.NONE);
+ tr2.setText(se1.getClassName());
+ tr2.setData(se1);
+
+ TableItem tr3 = new TableItem(table, SWT.NONE);
+ tr3.setText(se2.getClassName());
+ tr3.setData(se2);
+ }
+
+ protected String updateTree() {
+ TreeItem[] trs = tree.getSelection();
+ if (null == trs || trs.length <= 0) {
+ System.out.println("selection is bull");
+ return null;
+ }
+ TreeItem selected = trs[0];
+
+ SelectorElement se = (SelectorElement) selected.getData();
+
+ StringBuffer strBuf = new StringBuffer();
+ strBuf.append("DOM|").append(se.getId()).append("|")
+ .append(se.getDepth());
+
+ strBuf.append("|").append(combo.getText());
+ return strBuf.toString();
+ }
+
+ protected String updateTable() {
+ TableItem[] trs = table.getSelection();
+ if (null == trs || trs.length <= 0) {
+ System.out.println("selection is bull");
+ return null;
+ }
+ TableItem selected = trs[0];
+
+ SelectorElement se = (SelectorElement) selected.getData();
+
+ StringBuffer strBuf = new StringBuffer();
+ strBuf.append("CLASS|").append(se.getId()).append("|")
+ .append(se.getClassName());
+
+ strBuf.append("|").append(combo.getText());
+ return strBuf.toString();
+ }
+}
--- /dev/null
+package org.tizen.webuibuilder.ui.selector;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SelectorElement {
+ private String id = null;
+ private String tagName = null;
+ private String className = null;
+ private List<SelectorElement> children = null;
+ private SelectorElement parent = null;
+
+ public SelectorElement() {
+ children = new ArrayList<SelectorElement>();
+ }
+
+ public SelectorElement(String id, String tag, String cls, SelectorElement parent) {
+ this();
+ this.parent = parent;
+ this.id = id;
+ this.tagName = tag;
+ this.className = cls;
+ }
+
+ public String getTagName() {
+ return tagName;
+ }
+
+ public void setTagName(String tagName) {
+ this.tagName = tagName;
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ public List<SelectorElement> getChildren() {
+ return children;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public SelectorElement getParent() {
+ return parent;
+ }
+
+ public void setParent(SelectorElement parent) {
+ this.parent = parent;
+ }
+
+ public String getDepth() {
+ StringBuffer buffer = new StringBuffer();
+ getParentString(buffer);
+
+ return buffer.toString();
+ }
+
+ private void getParentString(StringBuffer buffer) {
+ if (null != parent) {
+ parent.getParentString(buffer);
+ }
+ buffer.append(">").append(this.tagName);
+ }
+}