diff options
author | Thomas Schindl | 2010-05-17 16:10:16 +0000 |
---|---|---|
committer | Thomas Schindl | 2010-05-17 16:10:16 +0000 |
commit | 0b982a7c8e0f8b01e76926790dc63c7156fb30e7 (patch) | |
tree | 3a52aafdcbe0f8957261952bd5c524ec3eb69f6e | |
parent | bb4dc817156c3e4e4861795c36c72a501ba565b5 (diff) | |
download | org.eclipse.e4.tools-0b982a7c8e0f8b01e76926790dc63c7156fb30e7.tar.gz org.eclipse.e4.tools-0b982a7c8e0f8b01e76926790dc63c7156fb30e7.tar.xz org.eclipse.e4.tools-0b982a7c8e0f8b01e76926790dc63c7156fb30e7.zip |
[Bug 304584] - [Tooling] Implement Workbench-Model-Tooling
* adding support for context variables
5 files changed, 243 insertions, 115 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java index 32762c9c..63842cab 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java @@ -67,6 +67,7 @@ public class Messages { public static String ControlFactory_Tags; public static String ControlFactory_Key; public static String ControlFactory_Value; + public static String ControlFactory_ContextVariables; public static String DirectToolItemEditor_ClassURI; public static String DirectToolItemEditor_Find; @@ -305,7 +306,6 @@ public class Messages { public static String ContributionClassDialog_DialogTitle; public static String ContributionClassDialog_Label_Classname; public static String ContributionClassDialog_ShellTitle; - static { diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties index 938e2ca6..78ac0a14 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties @@ -62,6 +62,7 @@ ControlFactory_Remove=Remove ControlFactory_Tags=Tags ControlFactory_Key=Key ControlFactory_Value=Value +ControlFactory_ContextVariables=Context Variables DirectToolItemEditor_ClassURI=Class URI DirectToolItemEditor_Find=Find ... diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java index 688533ee..832c277f 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/ControlFactory.java @@ -19,6 +19,7 @@ import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.MApplicationElement; import org.eclipse.e4.ui.model.application.commands.impl.CommandsPackageImpl; import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl; +import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.databinding.EMFProperties; import org.eclipse.emf.databinding.IEMFListProperty; @@ -46,131 +47,255 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; public class ControlFactory { - public static void createBindingsWidget(Composite parent, final AbstractComponentEditor editor) { - Label l = new Label(parent, SWT.NONE); - l.setText(Messages.ControlFactory_BindingContexts); - l.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - - final Text t = new Text(parent, SWT.BORDER); - t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - t.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.keyCode == SWT.CR || e.keyCode == SWT.LF) { - handleAddText( editor, CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS, t); - } + public static void createVariablesWidget(Composite parent, final AbstractComponentEditor editor) { + Label l = new Label(parent, SWT.NONE); + l.setText(Messages.ControlFactory_ContextVariables); + l.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + + final Text t = new Text(parent, SWT.BORDER); + t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + t.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.keyCode == SWT.CR || e.keyCode == SWT.LF) { + handleAddText(editor, UiPackageImpl.Literals.CONTEXT__VARIABLES, t); } - }); - - Button b = new Button(parent, SWT.PUSH | SWT.FLAT); - b.setText(Messages.ControlFactory_Add); - b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.TABLE_ADD_IMAGE)); - b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false)); - b.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - handleAddText( editor, CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS, t); + } + }); + + Button b = new Button(parent, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Add); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.TABLE_ADD_IMAGE)); + b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false)); + b.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + handleAddText(editor, UiPackageImpl.Literals.CONTEXT__VARIABLES, t); + } + }); + + new Label(parent, SWT.NONE); + + final TableViewer viewer = new TableViewer(parent); + viewer.setLabelProvider(new LabelProvider()); + viewer.setContentProvider(new ObservableListContentProvider()); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.heightHint = 150; + viewer.getControl().setLayoutData(gd); + + IEMFListProperty prop = EMFProperties.list(UiPackageImpl.Literals.CONTEXT__VARIABLES); + viewer.setInput(prop.observeDetail(editor.getMaster())); + + Composite buttonComp = new Composite(parent, SWT.NONE); + buttonComp.setLayoutData(new GridData(GridData.FILL, GridData.END, false, false)); + GridLayout gl = new GridLayout(); + gl.marginLeft = 0; + gl.marginRight = 0; + gl.marginWidth = 0; + gl.marginHeight = 0; + buttonComp.setLayout(gl); + + b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Up); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.ARROW_UP)); + b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + b.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (!viewer.getSelection().isEmpty()) { + IStructuredSelection s = (IStructuredSelection) viewer.getSelection(); + if (s.size() == 1) { + Object obj = s.getFirstElement(); + MApplication container = (MApplication) editor.getMaster().getValue(); + int idx = container.getCommands().indexOf(obj) - 1; + if (idx >= 0) { + Command cmd = MoveCommand.create(editor.getEditingDomain(), editor.getMaster().getValue(), UiPackageImpl.Literals.CONTEXT__VARIABLES, obj, idx); + + if (cmd.canExecute()) { + editor.getEditingDomain().getCommandStack().execute(cmd); + viewer.setSelection(new StructuredSelection(obj)); + } + } + + } } - }); - - new Label(parent, SWT.NONE); - - final TableViewer viewer = new TableViewer(parent); - viewer.setLabelProvider(new LabelProvider()); - viewer.setContentProvider(new ObservableListContentProvider()); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.heightHint = 150; - viewer.getControl().setLayoutData(gd); - - IEMFListProperty prop = EMFProperties.list(CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS); - viewer.setInput(prop.observeDetail(editor.getMaster())); - - Composite buttonComp = new Composite(parent, SWT.NONE); - buttonComp.setLayoutData(new GridData(GridData.FILL,GridData.END,false,false)); - GridLayout gl = new GridLayout(); - gl.marginLeft=0; - gl.marginRight=0; - gl.marginWidth=0; - gl.marginHeight=0; - buttonComp.setLayout(gl); - - b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); - b.setText(Messages.ControlFactory_Up); - b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.ARROW_UP)); - b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - b.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if( ! viewer.getSelection().isEmpty() ) { - IStructuredSelection s = (IStructuredSelection)viewer.getSelection(); - if( s.size() == 1 ) { - Object obj = s.getFirstElement(); - MApplication container = (MApplication) editor.getMaster().getValue(); - int idx = container.getCommands().indexOf(obj) - 1; - if( idx >= 0 ) { - Command cmd = MoveCommand.create(editor.getEditingDomain(), editor.getMaster().getValue(), CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS, obj, idx); - - if( cmd.canExecute() ) { - editor.getEditingDomain().getCommandStack().execute(cmd); - viewer.setSelection(new StructuredSelection(obj)); - } + } + }); + + b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Down); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.ARROW_DOWN)); + b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + b.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (!viewer.getSelection().isEmpty()) { + IStructuredSelection s = (IStructuredSelection) viewer.getSelection(); + if (s.size() == 1) { + Object obj = s.getFirstElement(); + MApplication container = (MApplication) editor.getMaster().getValue(); + int idx = container.getCommands().indexOf(obj) + 1; + if (idx < container.getCommands().size()) { + Command cmd = MoveCommand.create(editor.getEditingDomain(), editor.getMaster().getValue(), UiPackageImpl.Literals.CONTEXT__VARIABLES, obj, idx); + + if (cmd.canExecute()) { + editor.getEditingDomain().getCommandStack().execute(cmd); + viewer.setSelection(new StructuredSelection(obj)); } - } + } } - }); - - b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); - b.setText(Messages.ControlFactory_Down); - b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.ARROW_DOWN)); - b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - b.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if( ! viewer.getSelection().isEmpty() ) { - IStructuredSelection s = (IStructuredSelection)viewer.getSelection(); - if( s.size() == 1 ) { - Object obj = s.getFirstElement(); - MApplication container = (MApplication) editor.getMaster().getValue(); - int idx = container.getCommands().indexOf(obj) + 1; - if( idx < container.getCommands().size() ) { - Command cmd = MoveCommand.create(editor.getEditingDomain(), editor.getMaster().getValue(), CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS, obj, idx); - - if( cmd.canExecute() ) { - editor.getEditingDomain().getCommandStack().execute(cmd); - viewer.setSelection(new StructuredSelection(obj)); - } + } + }); + + b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Remove); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.TABLE_DELETE_IMAGE)); + b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + b.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (!viewer.getSelection().isEmpty()) { + MApplication el = (MApplication) editor.getMaster().getValue(); + List<?> ids = ((IStructuredSelection) viewer.getSelection()).toList(); + Command cmd = RemoveCommand.create(editor.getEditingDomain(), el, UiPackageImpl.Literals.CONTEXT__VARIABLES, ids); + if (cmd.canExecute()) { + editor.getEditingDomain().getCommandStack().execute(cmd); + if (el.getBindingContexts().size() > 0) { + viewer.setSelection(new StructuredSelection(el.getBindingContexts().get(0))); + } + } + } + } + }); + } + + public static void createBindingsWidget(Composite parent, final AbstractComponentEditor editor) { + Label l = new Label(parent, SWT.NONE); + l.setText(Messages.ControlFactory_BindingContexts); + l.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + + final Text t = new Text(parent, SWT.BORDER); + t.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + t.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.keyCode == SWT.CR || e.keyCode == SWT.LF) { + handleAddText(editor, CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS, t); + } + } + }); + + Button b = new Button(parent, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Add); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.TABLE_ADD_IMAGE)); + b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false)); + b.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + handleAddText(editor, CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS, t); + } + }); + + new Label(parent, SWT.NONE); + + final TableViewer viewer = new TableViewer(parent); + viewer.setLabelProvider(new LabelProvider()); + viewer.setContentProvider(new ObservableListContentProvider()); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.heightHint = 150; + viewer.getControl().setLayoutData(gd); + + IEMFListProperty prop = EMFProperties.list(CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS); + viewer.setInput(prop.observeDetail(editor.getMaster())); + + Composite buttonComp = new Composite(parent, SWT.NONE); + buttonComp.setLayoutData(new GridData(GridData.FILL, GridData.END, false, false)); + GridLayout gl = new GridLayout(); + gl.marginLeft = 0; + gl.marginRight = 0; + gl.marginWidth = 0; + gl.marginHeight = 0; + buttonComp.setLayout(gl); + + b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Up); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.ARROW_UP)); + b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + b.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (!viewer.getSelection().isEmpty()) { + IStructuredSelection s = (IStructuredSelection) viewer.getSelection(); + if (s.size() == 1) { + Object obj = s.getFirstElement(); + MApplication container = (MApplication) editor.getMaster().getValue(); + int idx = container.getCommands().indexOf(obj) - 1; + if (idx >= 0) { + Command cmd = MoveCommand.create(editor.getEditingDomain(), editor.getMaster().getValue(), CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS, obj, idx); + + if (cmd.canExecute()) { + editor.getEditingDomain().getCommandStack().execute(cmd); + viewer.setSelection(new StructuredSelection(obj)); } - } + } } - }); - - b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); - b.setText(Messages.ControlFactory_Remove); - b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.TABLE_DELETE_IMAGE)); - b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - b.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if( ! viewer.getSelection().isEmpty() ) { - MApplication el = (MApplication) editor.getMaster().getValue(); - List<?> ids = ((IStructuredSelection)viewer.getSelection()).toList(); - Command cmd = RemoveCommand.create(editor.getEditingDomain(), el, CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS, ids); - if( cmd.canExecute() ) { - editor.getEditingDomain().getCommandStack().execute(cmd); - if( el.getBindingContexts().size() > 0 ) { - viewer.setSelection(new StructuredSelection(el.getBindingContexts().get(0))); + } + }); + + b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Down); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.ARROW_DOWN)); + b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + b.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (!viewer.getSelection().isEmpty()) { + IStructuredSelection s = (IStructuredSelection) viewer.getSelection(); + if (s.size() == 1) { + Object obj = s.getFirstElement(); + MApplication container = (MApplication) editor.getMaster().getValue(); + int idx = container.getCommands().indexOf(obj) + 1; + if (idx < container.getCommands().size()) { + Command cmd = MoveCommand.create(editor.getEditingDomain(), editor.getMaster().getValue(), CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS, obj, idx); + + if (cmd.canExecute()) { + editor.getEditingDomain().getCommandStack().execute(cmd); + viewer.setSelection(new StructuredSelection(obj)); } } + } } - }); + } + }); + + b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); + b.setText(Messages.ControlFactory_Remove); + b.setImage(editor.getImage(b.getDisplay(), AbstractComponentEditor.TABLE_DELETE_IMAGE)); + b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + b.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (!viewer.getSelection().isEmpty()) { + MApplication el = (MApplication) editor.getMaster().getValue(); + List<?> ids = ((IStructuredSelection) viewer.getSelection()).toList(); + Command cmd = RemoveCommand.create(editor.getEditingDomain(), el, CommandsPackageImpl.Literals.BINDINGS__BINDING_CONTEXTS, ids); + if (cmd.canExecute()) { + editor.getEditingDomain().getCommandStack().execute(cmd); + if (el.getBindingContexts().size() > 0) { + viewer.setSelection(new StructuredSelection(el.getBindingContexts().get(0))); + } + } + } + } + }); } - - public static void createTagsWidget( Composite parent, final AbstractComponentEditor editor ) { + + public static void createTagsWidget(Composite parent, final AbstractComponentEditor editor) { Label l = new Label(parent, SWT.NONE); l.setText(Messages.ControlFactory_Tags); l.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false)); @@ -240,10 +365,10 @@ public class ControlFactory { @Override public void widgetSelected(SelectionEvent e) { IStructuredSelection s = (IStructuredSelection) viewer.getSelection(); - if( ! s.isEmpty() ) { + if (!s.isEmpty()) { MApplicationElement appEl = (MApplicationElement) editor.getMaster().getValue(); Command cmd = RemoveCommand.create(editor.getEditingDomain(), appEl, ApplicationPackageImpl.Literals.APPLICATION_ELEMENT__TAGS, s.toList()); - if( cmd.canExecute() ) { + if (cmd.canExecute()) { editor.getEditingDomain().getCommandStack().execute(cmd); } } @@ -251,10 +376,10 @@ public class ControlFactory { }); } - private static void handleAddText( AbstractComponentEditor editor, EStructuralFeature feature, Text tagText) { + private static void handleAddText(AbstractComponentEditor editor, EStructuralFeature feature, Text tagText) { if (tagText.getText().trim().length() > 0) { String[] tags = tagText.getText().split(";"); //$NON-NLS-1$ - for( int i = 0; i < tags.length;i++ ) { + for (int i = 0; i < tags.length; i++) { tags[i] = tags[i].trim(); } diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartEditor.java index e1189335..43171383 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/PartEditor.java @@ -319,6 +319,7 @@ public class PartEditor extends AbstractComponentEditor { b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); } + ControlFactory.createVariablesWidget(parent, this); ControlFactory.createTagsWidget(parent, this); return parent; diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java index 0efb8590..479e9fb0 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/WindowEditor.java @@ -237,6 +237,7 @@ public class WindowEditor extends AbstractComponentEditor { } ControlFactory.createBindingsWidget(parent, this); + ControlFactory.createVariablesWidget(parent, this); ControlFactory.createTagsWidget(parent, this); return parent; |