### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.runtime.emf.ui Index: src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.properties =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.emf.ui/src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.properties,v retrieving revision 1.3 diff -u -r1.3 EMFUIMessages.properties --- src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.properties 7 Apr 2006 14:51:21 -0000 1.3 +++ src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.properties 24 May 2006 16:55:14 -0000 @@ -74,4 +74,5 @@ PathmapsPreferencePage_addAllChevron=\ >> PathmapsPreferencePage_removeAllChevron=\ << PathmapsPreferencePage_incompatiblePathVariableErrorMessage=The selected path variable(s) cannot be supported in a modeling environment. +PathmapsPreferencePage_registeredPathVariableErrorMessage=The selected path variable(s) are defined by the system; they cannot be removed. # ==================================== END ================================================= Index: src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.emf.ui/src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.java,v retrieving revision 1.3 diff -u -r1.3 EMFUIMessages.java --- src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.java 7 Apr 2006 14:51:21 -0000 1.3 +++ src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.java 24 May 2006 16:55:14 -0000 @@ -49,6 +49,7 @@ public static String PathmapsPreferencePage_addChevron; public static String PathmapsPreferencePage_removeChevron; public static String PathmapsPreferencePage_incompatiblePathVariableErrorMessage; + public static String PathmapsPreferencePage_registeredPathVariableErrorMessage; public static String PathmapsPreferencePage_mainDescription; public static String PathmapsPreferencePage_addAllChevron; public static String PathmapsPreferencePage_removeAllChevron; Index: src/org/eclipse/gmf/runtime/emf/ui/preferences/PathmapsPreferencePage.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.emf.ui/src/org/eclipse/gmf/runtime/emf/ui/preferences/PathmapsPreferencePage.java,v retrieving revision 1.4 diff -u -r1.4 PathmapsPreferencePage.java --- src/org/eclipse/gmf/runtime/emf/ui/preferences/PathmapsPreferencePage.java 24 May 2006 14:54:48 -0000 1.4 +++ src/org/eclipse/gmf/runtime/emf/ui/preferences/PathmapsPreferencePage.java 24 May 2006 16:55:14 -0000 @@ -11,7 +11,9 @@ package org.eclipse.gmf.runtime.emf.ui.preferences; +import java.util.HashSet; import java.util.Iterator; +import java.util.Set; import org.eclipse.core.resources.IPathVariableChangeEvent; import org.eclipse.core.resources.IPathVariableChangeListener; @@ -19,16 +21,33 @@ import org.eclipse.gmf.runtime.emf.core.internal.resources.PathmapManager; import org.eclipse.gmf.runtime.emf.ui.internal.l10n.EMFUIMessages; import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.viewers.IColorProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.TableColumn; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.dialogs.PreferenceLinkArea; @@ -46,9 +65,14 @@ public class PathmapsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { - private List referencedPathVariables; - private List pathVariables; + private ScrolledComposite referencedPathVariablesScroll; + private TableViewer referencedPathVariables; + private StringsContentProvider referencedPathVariablesContent; + private ScrolledComposite pathVariablesScroll; + private TableViewer pathVariables; + private StringsContentProvider pathVariablesContent; private Button add; + private Button remove; private IPathVariableChangeListener pathVariableChangeListener; private boolean disposed = true; @@ -77,7 +101,7 @@ gridData.grabExcessVerticalSpace = false; gridData.horizontalSpan = 3; pathVariablesArea.getControl().setLayoutData(gridData); - + Composite pathVariablesComposite = new Composite(composite, SWT.NONE); pathVariablesComposite.setLayout(new GridLayout(1, false)); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); @@ -95,12 +119,30 @@ pathVariablesLabel.setLayoutData(gridData); pathVariablesLabel.setText(EMFUIMessages.PathmapsPreferencePage_availablePathVariables); - pathVariables = new List(pathVariablesComposite, SWT.MULTI | SWT.BORDER); + pathVariablesScroll = new ScrolledComposite( + pathVariablesComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + pathVariablesScroll.setExpandHorizontal(true); + pathVariablesScroll.setExpandVertical(true); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalSpan = 1; - pathVariables.setLayoutData(gridData); + pathVariablesScroll.setLayoutData(gridData); + pathVariables = new TableViewer(pathVariablesScroll, SWT.MULTI); + pathVariablesScroll.setContent(pathVariables.getTable()); + + TableColumn column = new TableColumn(pathVariables.getTable(), SWT.LEFT); + column.setMoveable(false); + column.setResizable(false); + pathVariables.getTable().addControlListener(new ControlAdapter() { + public void controlResized(ControlEvent e) { + pathVariables.getTable().getColumn(0).setWidth( + pathVariables.getTable().getClientArea().width); + }}); + pathVariablesContent = new StringsContentProvider(); + pathVariables.setContentProvider(pathVariablesContent); + pathVariables.setLabelProvider(new StringsLabelProvider()); + pathVariables.setComparator(new StringsViewerComparator()); Composite buttonComposite = new Composite(composite, SWT.NONE); buttonComposite.setLayout(new GridLayout(1, false)); @@ -117,7 +159,7 @@ gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = false; addAll.setLayoutData(gridData); - Button remove = new Button(buttonComposite,SWT.CENTER); + remove = new Button(buttonComposite,SWT.CENTER); remove.setText(EMFUIMessages.PathmapsPreferencePage_removeChevron); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.grabExcessHorizontalSpace = true; @@ -156,50 +198,79 @@ referencedPathVariablesLabel.setLayoutData(gridData); referencedPathVariablesLabel.setText(EMFUIMessages.PathmapsPreferencePage_pathVariablesUsedInModeling); - referencedPathVariables = new List(referencedPathVariablesComposite,SWT.MULTI | SWT.BORDER); + referencedPathVariablesScroll = new ScrolledComposite( + referencedPathVariablesComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + referencedPathVariablesScroll.setExpandHorizontal(true); + referencedPathVariablesScroll.setExpandVertical(true); gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; gridData.horizontalSpan = 1; - referencedPathVariables.setLayoutData(gridData); - - pathVariables.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - referencedPathVariables.deselectAll(); - - if (!validateSelections(pathVariables.getSelection())) { - setMessage(EMFUIMessages.PathmapsPreferencePage_incompatiblePathVariableErrorMessage,ERROR); - add.setEnabled(false); - } else { - setMessage(null); - add.setEnabled(true); + referencedPathVariablesScroll.setLayoutData(gridData); + referencedPathVariables = new TableViewer(referencedPathVariablesScroll, SWT.MULTI); + referencedPathVariablesScroll.setContent(referencedPathVariables.getTable()); + + column = new TableColumn(referencedPathVariables.getTable(), SWT.LEFT); + column.setMoveable(false); + column.setResizable(false); + referencedPathVariables.getTable().addControlListener(new ControlAdapter() { + public void controlResized(ControlEvent e) { + referencedPathVariables.getTable().getColumn(0).setWidth( + referencedPathVariables.getTable().getClientArea().width); + }}); + referencedPathVariablesContent = new StringsContentProvider(); + referencedPathVariables.setContentProvider(referencedPathVariablesContent); + referencedPathVariables.setLabelProvider(new StringsLabelProvider(true)); + referencedPathVariables.setComparator(new StringsViewerComparator()); + + // adjust the scroll bars whenever the preference page is resized + composite.addControlListener(new ControlAdapter() { + public void controlResized(ControlEvent e) { + adjustScrollpanes(); + }}); + + pathVariables.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + if (!event.getSelection().isEmpty()) { // prevent oscillation + referencedPathVariables.setSelection(new StructuredSelection()); + remove.setEnabled(true); + + if (!validateAdditions((IStructuredSelection) event.getSelection(), true)) { + add.setEnabled(false); + } else { + setMessage(null); + add.setEnabled(true); + } } } - - public void widgetDefaultSelected(SelectionEvent e) { - // No action necessary - } }); - referencedPathVariables.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - setMessage(null); - add.setEnabled(true); - pathVariables.deselectAll(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - // No action necessary + referencedPathVariables.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + if (!event.getSelection().isEmpty()) { // prevent oscillation + add.setEnabled(true); + pathVariables.setSelection(new StructuredSelection()); + + if (!validateRemovals((IStructuredSelection) event.getSelection(), true)) { + remove.setEnabled(false); + } else { + setMessage(null); + remove.setEnabled(true); + } + } } }); add.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { - String[] selections = pathVariables.getSelection(); + IStructuredSelection selection = + (IStructuredSelection) pathVariables.getSelection(); - for (int i=0; i= 0; i--) { + if (validateAdditions(new StructuredSelection(items[i]), false)) { + String name = (String) items[i]; + pathVariablesContent.remove(name); + referencedPathVariablesContent.add(name); + adjustScrollpanes(); } } } @@ -227,11 +300,14 @@ remove.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { - String[] selections = referencedPathVariables.getSelection(); + IStructuredSelection selection = + (IStructuredSelection) referencedPathVariables.getSelection(); - for (int i=0; i= 0; i--) { + if (validateRemovals(new StructuredSelection(items[i]), false)) { + String name = (String) items[i]; + referencedPathVariablesContent.remove(name); + pathVariablesContent.add(name); + adjustScrollpanes(); + } } } }); @@ -261,7 +341,7 @@ // the up-to-date information. pathVariableChangeListener = new IPathVariableChangeListener() { public void pathVariableChanged(IPathVariableChangeEvent event) { - referencedPathVariables.getShell().getDisplay().asyncExec(new Runnable() { + referencedPathVariables.getTable().getDisplay().asyncExec(new Runnable() { public void run() { if (!PathmapsPreferencePage.this.disposed) { performDefaults(); @@ -279,14 +359,50 @@ return composite; } - private boolean validateSelections(String[] selections) { - if (selections.length == 0) + private void adjustScrollpanes() { + pathVariablesScroll.setMinSize( + pathVariables.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT)); + pathVariablesScroll.layout(); + referencedPathVariablesScroll.setMinSize( + referencedPathVariables.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT)); + referencedPathVariablesScroll.layout(); + } + + private boolean validateAdditions(IStructuredSelection selection, boolean showError) { + if (selection.isEmpty()) return false; - for (int i=0; itrue if this variable name is registered on the + * path maps extension point; false, otherwise + */ + public static boolean isRegisteredPathVariable(String variable) { + return PATH_MAP.containsKey(variable) + && !referencedPathVariablesList.contains(variable); + } + public static boolean isCompatiblePathVariable(String variable) { if (referencedPathVariablesList.contains(variable)) { // We assume that if this variable is already referenced then it is valid.