diff options
author | Steven Spungin | 2014-04-24 13:17:30 +0000 |
---|---|---|
committer | Lars Vogel | 2014-05-06 19:01:08 +0000 |
commit | 39b256f472d87f540db485117f6b32c2fc2f9135 (patch) | |
tree | 666f85a9f1bb15a17753439cc3d1b79ccbd15f19 | |
parent | 27e6572c59925d736dff2a42a246ec0fcefcaebb (diff) | |
download | org.eclipse.e4.tools-39b256f472d87f540db485117f6b32c2fc2f9135.tar.gz org.eclipse.e4.tools-39b256f472d87f540db485117f6b32c2fc2f9135.tar.xz org.eclipse.e4.tools-39b256f472d87f540db485117f6b32c2fc2f9135.zip |
Bug 430717 - Changes To The StringListWidgetI20140507-2200I20140506-2200
New Feature: Changes To The StringListWidget
Added a replace button
Selecting an item in the list populates the text box
UI State to disable buttons that have no effect
Added new string to Message.properties
Change-Id: Icf513da1a73e2ee88c9aaa5bd8a055bfc2a6c573
Signed-off-by: Steven Spungin <steven@spungin.tv>
3 files changed, 114 insertions, 31 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 cff7214b..8f96ada0 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 @@ -8,7 +8,7 @@ * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation * Marco Descher <marco@descher.at> - Bug 395982, 396975, 426653 - * Steven Spungin <steven@spungin.tv> - Bug 431735 + * Steven Spungin <steven@spungin.tv> - Bug 431735, 430717 ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal; @@ -20,6 +20,7 @@ public class Messages { public String ModelTooling_Common_AddEllipsis; public String ModelTooling_Common_Add; public String ModelTooling_Common_Remove; + public String ModelTooling_Common_Replace; public String ModelTooling_Common_Id; public String ModelTooling_Common_RefId; public String ModelTooling_Common_FindEllipsis; 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 f59984c0..77a4a81d 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 @@ -9,13 +9,14 @@ # * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation # * Sopot Cela <sopotcela@gmail.com> - enhancements # * Marco Descher <marco@descher.at> - Bug 395982, 396975, 426653 -# * Steven Spungin <steven@spungin.tv> - Bug 431735 +# * Steven Spungin <steven@spungin.tv> - Bug 431735, 430717 # ****************************************************************************** ModelTooling_Common_Up=Up ModelTooling_Common_Down=Down ModelTooling_Common_AddEllipsis=Add ... ModelTooling_Common_Add=Add ModelTooling_Common_Remove=Remove +ModelTooling_Common_Replace=Replace ModelTooling_Common_Id=ID ModelTooling_Common_RefId=Reference-ID ModelTooling_Common_FindEllipsis=Find ... @@ -494,10 +495,7 @@ VWindowTrimEditor_TreeLabelDescription=Window Trims Bla Bla Bla Bla Bla VWindowTrimEditor_Controls=Controls VWindowTrimEditor_AddWindowTrim=Window Trim -AbstractIconDialog_IconName=Icon Name -AbstractIconDialog_all_workspace_bundles=All Workspace Bundles -AbstractIconDialog_current_project=Current Project -AbstractIconDialog_scope=Scope +AbstractIconDialog_IconName=IconName BindingContextSelectionDialog_ShellTitle=BindingContext Dialog BindingContextSelectionDialog_Title=BindingContext 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 6775e46d..645a07c8 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 @@ -8,7 +8,7 @@ * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation * Dirk Fauth <dirk.fauth@googlemail.com> - Bug 426986 - * Steven Spungin <steven@spungin.tv> - Bug 430660, 430664, Bug 430809 + * Steven Spungin <steven@spungin.tv> - Bug 430660, 430664, Bug 430809, 430717 ******************************************************************************/ package org.eclipse.e4.tools.emf.ui.internal.common.component; @@ -78,8 +78,10 @@ import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; @@ -716,13 +718,13 @@ public class ControlFactory { TextPasteHandler.createFor(t); - Button b = new Button(parent, SWT.PUSH | SWT.FLAT); - b.setText(Messages.ModelTooling_Common_Add); - b.setImage(editor.createImage(ResourceProvider.IMG_Obj16_table_add)); + final Button btnAdd = new Button(parent, SWT.PUSH | SWT.FLAT); + btnAdd.setText(Messages.ModelTooling_Common_Add); + btnAdd.setImage(editor.createImage(ResourceProvider.IMG_Obj16_table_add)); gd = new GridData(GridData.FILL, GridData.CENTER, false, false); gd.verticalIndent = vIndent; - b.setLayoutData(gd); - b.addSelectionListener(new SelectionAdapter() { + btnAdd.setLayoutData(gd); + btnAdd.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { handleAddText(editor, feature, t); @@ -740,21 +742,43 @@ public class ControlFactory { IEMFListProperty prop = EMFProperties.list(feature); viewer.setInput(prop.observeDetail(editor.getMaster())); + viewer.addSelectionChangedListener(new ISelectionChangedListener() { - Composite buttonComp = new Composite(parent, SWT.NONE); - buttonComp.setLayoutData(new GridData(GridData.FILL, GridData.END, false, false)); + @Override + public void selectionChanged(SelectionChangedEvent event) { + String strSelected = (String) ((StructuredSelection) event.getSelection()).getFirstElement(); + t.setText(strSelected != null ? strSelected : ""); //$NON-NLS-1$ + } + }); + + Composite compButton = new Composite(parent, SWT.NONE); + compButton.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); + compButton.setLayout(gl); - b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); - b.setText(Messages.ModelTooling_Common_Up); - b.setImage(editor.createImage(ResourceProvider.IMG_Obj16_arrow_up)); - b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - b.addSelectionListener(new SelectionAdapter() { + final Button btnReplace = new Button(compButton, SWT.PUSH | SWT.FLAT); + // TODO need to add icon for replace + btnReplace.setText(Messages.ModelTooling_Common_Replace); + btnReplace.setImage(editor.createImage(ResourceProvider.IMG_Obj16_table_add)); + gd = new GridData(GridData.FILL, GridData.CENTER, false, false); + gd.verticalIndent = vIndent; + btnReplace.setLayoutData(gd); + btnReplace.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + handleReplaceText(editor, feature, t, viewer); + } + }); + + final Button btnUp = new Button(compButton, SWT.PUSH | SWT.FLAT); + btnUp.setText(Messages.ModelTooling_Common_Up); + btnUp.setImage(editor.createImage(ResourceProvider.IMG_Obj16_arrow_up)); + btnUp.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + btnUp.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!viewer.getSelection().isEmpty()) { @@ -778,11 +802,11 @@ public class ControlFactory { } }); - b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); - b.setText(Messages.ModelTooling_Common_Down); - b.setImage(editor.createImage(ResourceProvider.IMG_Obj16_arrow_down)); - b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - b.addSelectionListener(new SelectionAdapter() { + final Button btnDown = new Button(compButton, SWT.PUSH | SWT.FLAT); + btnDown.setText(Messages.ModelTooling_Common_Down); + btnDown.setImage(editor.createImage(ResourceProvider.IMG_Obj16_arrow_down)); + btnDown.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + btnDown.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!viewer.getSelection().isEmpty()) { @@ -806,11 +830,11 @@ public class ControlFactory { } }); - b = new Button(buttonComp, SWT.PUSH | SWT.FLAT); - b.setText(Messages.ModelTooling_Common_Remove); - b.setImage(editor.createImage(ResourceProvider.IMG_Obj16_table_delete)); - b.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - b.addSelectionListener(new SelectionAdapter() { + final Button btnDelete = new Button(compButton, SWT.PUSH | SWT.FLAT); + btnDelete.setText(Messages.ModelTooling_Common_Remove); + btnDelete.setImage(editor.createImage(ResourceProvider.IMG_Obj16_table_delete)); + btnDelete.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); + btnDelete.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!viewer.getSelection().isEmpty()) { @@ -826,6 +850,38 @@ public class ControlFactory { } } }); + + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + + @Override + public void selectionChanged(SelectionChangedEvent event) { + updateUiState(viewer, t, btnAdd, btnReplace, btnDelete, btnDown, btnUp); + } + }); + + t.addModifyListener(new ModifyListener() { + + @Override + public void modifyText(ModifyEvent e) { + updateUiState(viewer, t, btnAdd, btnReplace, btnDelete, btnDown, btnUp); + } + }); + + updateUiState(viewer, t, btnAdd, btnReplace, btnDelete, btnDown, btnUp); + } + + private static void updateUiState(TableViewer viewer, Text t, Button btnAdd, Button btnReplace, Button btnDelete, Button btnDown, Button btnUp) { + IStructuredSelection sel = (IStructuredSelection) viewer.getSelection(); + Object firstViewerElement = sel.getFirstElement(); + boolean diff = !t.getText().equals(firstViewerElement); + + btnReplace.setEnabled(firstViewerElement != null && !t.getText().isEmpty() && diff); + // TODO check valid value and not already in list + btnAdd.setEnabled(!t.getText().isEmpty()); + + btnUp.setEnabled(firstViewerElement != null); + btnDown.setEnabled(firstViewerElement != null); + btnDelete.setEnabled(firstViewerElement != null); } private static void handleAddText(AbstractComponentEditor editor, EStructuralFeature feature, Text tagText) { @@ -844,6 +900,34 @@ public class ControlFactory { } } + private static void handleReplaceText(AbstractComponentEditor editor, EStructuralFeature feature, Text tagText, TableViewer viewer) { + if (tagText.getText().trim().length() > 0) { + if (!viewer.getSelection().isEmpty()) { + String[] tags = tagText.getText().split(";"); //$NON-NLS-1$ + for (int i = 0; i < tags.length; i++) { + tags[i] = tags[i].trim(); + } + + MApplicationElement appEl = (MApplicationElement) editor.getMaster().getValue(); + EObject el = (EObject) editor.getMaster().getValue(); + List<?> ids = ((IStructuredSelection) viewer.getSelection()).toList(); + Object curVal = ((IStructuredSelection) viewer.getSelection()).getFirstElement(); + EObject container = (EObject) editor.getMaster().getValue(); + List<?> l = (List<?>) container.eGet(feature); + int idx = l.indexOf(curVal); + if (idx >= 0) { + Command cmdRemove = RemoveCommand.create(editor.getEditingDomain(), el, feature, ids); + Command cmdInsert = AddCommand.create(editor.getEditingDomain(), appEl, feature, Arrays.asList(tags), idx); + if (cmdRemove.canExecute() && cmdInsert.canExecute()) { + editor.getEditingDomain().getCommandStack().execute(cmdRemove); + editor.getEditingDomain().getCommandStack().execute(cmdInsert); + } + tagText.setText(""); //$NON-NLS-1$ + } + } + } + } + public static void createCheckBox(Composite parent, String label, IObservableValue master, EMFDataBindingContext context, IWidgetValueProperty selectionProp, IEMFEditValueProperty modelProp) { createCheckBox(parent, label, null, master, context, selectionProp, modelProp); } @@ -914,4 +998,4 @@ public class ControlFactory { } }); } -} +}
\ No newline at end of file |