Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 59365 Details for
Bug 159650
Pathmaps Preference Page is not easy to use
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Updated patch
bug159650.patch (text/plain), 79.63 KB, created by
Christian Damus
on 2007-02-20 08:18:06 EST
(
hide
)
Description:
Updated patch
Filename:
MIME Type:
Creator:
Christian Damus
Created:
2007-02-20 08:18:06 EST
Size:
79.63 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.gmf.runtime.emf.ui >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.5 >diff -u -r1.5 EMFUIMessages.java >--- src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.java 3 Oct 2006 15:06:39 -0000 1.5 >+++ src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.java 20 Feb 2007 13:14:45 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -45,15 +45,33 @@ > public static String Validation_dontShowCheck; > public static String Validation_outputProviderCategory; > public static String PathmapsPreferencePage_availablePathVariables; >- public static String PathmapsPreferencePage_pathVariablesUsedInModeling; >- public static String PathmapsPreferencePage_addChevron; >- public static String PathmapsPreferencePage_removeChevron; >+ public static String PathmapsPreferencePage_newVariable; >+ public static String PathmapsPreferencePage_editVariable; >+ public static String PathmapsPreferencePage_removeVariable; > 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; >+ public static String PathmapsPreferencePage_promptTitle; >+ public static String PathmapsPreferencePage_updateFailed; >+ public static String PathmapsPreferencePage_variablePattern; >+ public static String PathVariableDialog_newDialogTitle; >+ public static String PathVariableDialog_editDialogTitle; >+ public static String PathVariableDialog_newTitle; >+ public static String PathVariableDialog_editTitle; >+ public static String PathVariableDialog_newMessage; >+ public static String PathVariableDialog_editMessage; >+ public static String PathVariableDialog_nameLabel; >+ public static String PathVariableDialog_locationLabel; >+ public static String PathVariableDialog_browseButton; >+ public static String PathVariableDialog_browseDialogTitle; >+ public static String PathVariableDialog_browseDialogMessage; >+ public static String PathVariableDialog_alreadyDefined_ERROR_; >+ public static String PathVariableDialog_invalidSegment_ERROR_; >+ public static String PathVariableDialog_notFolder_ERROR_; >+ public static String PathVariableDialog_noSuchFolder_ERROR_; >+ public static String PathVariableDialog_sameLocation_WARN_; > >+ > static { > NLS.initializeMessages(BUNDLE_NAME, EMFUIMessages.class); > } >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.4 >diff -u -r1.4 EMFUIMessages.properties >--- src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.properties 24 May 2006 17:20:26 -0000 1.4 >+++ src/org/eclipse/gmf/runtime/emf/ui/internal/l10n/EMFUIMessages.properties 20 Feb 2007 13:14:45 -0000 >@@ -1,6 +1,6 @@ > # ============================================================================== > #*+------------------------------------------------------------------------+ >-#*| Copyright (c) 2005 IBM Corporation and others. | >+#*| Copyright (c) 2005, 2007 IBM Corporation and others. | > #*| All rights reserved. This program and the accompanying materials | > #*| are made available under the terms of the Eclipse Public License v1.0 | > #*| which accompanies this distribution, and is available at | >@@ -66,13 +66,44 @@ > # to be used in modeling. These messages are used in a preference page. > # > # ================================ BEGIN ================================================== >-PathmapsPreferencePage_mainDescription=Choose path variables defined in <a>''{0}''</a> to use for modeling artifacts. >-PathmapsPreferencePage_availablePathVariables=Available path variables: >-PathmapsPreferencePage_pathVariablesUsedInModeling=Path variables for modeling: >-PathmapsPreferencePage_addChevron=\ > >-PathmapsPreferencePage_removeChevron=\ < >-PathmapsPreferencePage_addAllChevron=\ >> >-PathmapsPreferencePage_removeAllChevron=\ << >+PathmapsPreferencePage_mainDescription=Use the check boxes to select path variables to use in modeling artifacts.\n\ >+These are a subset of the path variables in the ''<a>{0}</a>'' preferences page. >+PathmapsPreferencePage_availablePathVariables=Available path &variables: >+PathmapsPreferencePage_newVariable=&New... >+PathmapsPreferencePage_editVariable=&Edit... >+PathmapsPreferencePage_removeVariable=&Remove > 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. >+PathmapsPreferencePage_promptTitle=Path Map Variables >+PathmapsPreferencePage_updateFailed=Failed to update workspace path variables. >+# Pattern for display of path variables in the preference page. {0} is the >+# variable name and {1} is its value (the folder location). This pattern >+# corresponds to the display of Path Variables in the Linked Resources >+# preference page provided by the Eclipse Platform >+PathmapsPreferencePage_variablePattern={0} - {1} >+# ==================================== END ================================================= >+ >+# >+# Messages pertaining to the creation and editing of path variables >+# to be used in modeling. These messages are used in a modal dialog launched by >+# the preference page. >+# >+# ================================ BEGIN ================================================== >+PathVariableDialog_newDialogTitle=Create Path Variable >+PathVariableDialog_editDialogTitle=Edit Path Variable >+PathVariableDialog_newTitle=Define a new path variable >+PathVariableDialog_editTitle=Change an existing path variable >+PathVariableDialog_newMessage=Enter the name and location of a path variable. >+PathVariableDialog_editMessage=Edit the name and/or location of the path variable. >+PathVariableDialog_nameLabel=&Name: >+PathVariableDialog_locationLabel=&Folder: >+PathVariableDialog_browseButton=&Browse... >+PathVariableDialog_browseDialogTitle=Folder Selection >+PathVariableDialog_browseDialogMessage=Select a folder for the path variable location. >+PathVariableDialog_alreadyDefined_ERROR_=Path variable already defined. >+PathVariableDialog_invalidSegment_ERROR_=Path variable name is not a valid URI segment. >+PathVariableDialog_notFolder_ERROR_=Path variables for modeling must be folder locations. >+PathVariableDialog_noSuchFolder_ERROR_=Specified folder does not exist. >+PathVariableDialog_sameLocation_WARN_=Another path variable is already defined for this location. >+ > # ==================================== END ================================================= >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.7 >diff -u -r1.7 PathmapsPreferencePage.java >--- src/org/eclipse/gmf/runtime/emf/ui/preferences/PathmapsPreferencePage.java 9 Feb 2007 19:43:06 -0000 1.7 >+++ src/org/eclipse/gmf/runtime/emf/ui/preferences/PathmapsPreferencePage.java 20 Feb 2007 13:14:45 -0000 >@@ -11,23 +11,31 @@ > > package org.eclipse.gmf.runtime.emf.ui.preferences; > >+import java.io.File; >+import java.util.Arrays; >+import java.util.HashMap; > import java.util.HashSet; > import java.util.Iterator; >+import java.util.Map; > import java.util.Set; > >-import org.eclipse.core.resources.IPathVariableChangeEvent; >-import org.eclipse.core.resources.IPathVariableChangeListener; > import org.eclipse.core.resources.IPathVariableManager; > import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; >-import org.eclipse.emf.common.CommonPlugin; >+import org.eclipse.core.runtime.Path; > import org.eclipse.emf.common.util.URI; > import org.eclipse.gmf.runtime.emf.core.internal.resources.PathmapManager; > import org.eclipse.gmf.runtime.emf.ui.internal.MslUIPlugin; > import org.eclipse.gmf.runtime.emf.ui.internal.l10n.EMFUIMessages; >+import org.eclipse.jface.dialogs.ErrorDialog; > import org.eclipse.jface.preference.PreferencePage; >+import org.eclipse.jface.viewers.CheckStateChangedEvent; >+import org.eclipse.jface.viewers.CheckboxTableViewer; >+import org.eclipse.jface.viewers.ICheckStateListener; > import org.eclipse.jface.viewers.IColorProvider; > import org.eclipse.jface.viewers.ILabelProviderListener; >+import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.ISelectionChangedListener; > import org.eclipse.jface.viewers.IStructuredContentProvider; > import org.eclipse.jface.viewers.IStructuredSelection; >@@ -37,25 +45,20 @@ > import org.eclipse.jface.viewers.TableViewer; > import org.eclipse.jface.viewers.Viewer; > import org.eclipse.jface.viewers.ViewerComparator; >+import org.eclipse.osgi.util.NLS; > 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.MouseEvent; >-import org.eclipse.swt.events.MouseTrackAdapter; >+import org.eclipse.swt.events.SelectionAdapter; > 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.graphics.Point; > 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.Label; >-import org.eclipse.swt.widgets.TableColumn; >-import org.eclipse.swt.widgets.TableItem; >+import org.eclipse.ui.ISharedImages; > import org.eclipse.ui.IWorkbench; > import org.eclipse.ui.IWorkbenchPreferencePage; > import org.eclipse.ui.dialogs.PreferenceLinkArea; >@@ -64,584 +67,1035 @@ > /** > * Preference page for specifying the path variables that should be considered > * for modeling. >- * <P> >+ * <p> > * Path variable are created on the "Linked Resources" preference page, and > * selected for modeling using this page. >+ * </p> >+ * <p> >+ * This class may be instantiated by clients, but is not intended to be >+ * subclassed. >+ * </p> > * > * @author Chris McGee >+ * @autor Christian W. Damus (cdamus) > */ > public class PathmapsPreferencePage >- extends PreferencePage implements IWorkbenchPreferencePage { >+ extends PreferencePage >+ implements IWorkbenchPreferencePage { >+ >+ private static final String NAME_ATTRIBUTE = "name"; //$NON-NLS-1$ >+ >+ private IPathVariableManager pathVariableManager = ResourcesPlugin >+ .getWorkspace().getPathVariableManager(); >+ >+ private ScrolledComposite pathVariablesScroll; >+ >+ private CheckboxTableViewer pathVariables; >+ >+ private PathVariableContentProvider pathVariablesContent; >+ >+ private Button newVariable; >+ >+ private Button editVariable; >+ >+ private Button removeVariable; >+ >+ /** Path variable changes since last time the Apply button was pressed. */ >+ private Map variableChanges = new HashMap(); >+ >+ private Object addedToken = new Object(); >+ >+ private Object changedToken = new Object(); >+ >+ private Object removedToken = new Object(); >+ >+ protected void initHelp() { >+ // No context-sensitive help for now. >+ } >+ >+ protected Control createContents(Composite parent) { >+ GridData gridData = null; >+ Composite composite = new Composite(parent, SWT.NONE); >+ composite.setFont(parent.getFont()); >+ >+ composite.setLayout(new GridLayout(2, false)); > >- 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; >- >- protected void initHelp() { >- // No context-sensitive help for now. >- } >- >- protected Control createContents(Composite parent) { >- GridData gridData = null; >- Composite composite = new Composite(parent, SWT.NONE); >- composite.setFont(parent.getFont()); >- >- composite.setLayout(new GridLayout(3, false)); >- gridData = new GridData(GridData.FILL_HORIZONTAL); >- gridData.grabExcessHorizontalSpace = true; >- gridData.horizontalSpan = 2; >- composite.setLayoutData(gridData); >- > PreferenceLinkArea pathVariablesArea = new PreferenceLinkArea( > composite, > SWT.NONE, >- "org.eclipse.ui.preferencePages.LinkedResources", EMFUIMessages.PathmapsPreferencePage_mainDescription, //$NON-NLS-1$ >+ "org.eclipse.ui.preferencePages.LinkedResources", //$NON-NLS-1$ >+ EMFUIMessages.PathmapsPreferencePage_mainDescription, > (IWorkbenchPreferenceContainer) getContainer(), null); >- gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); >- gridData.grabExcessHorizontalSpace = true; >- 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); >- gridData.grabExcessHorizontalSpace = true; >- gridData.grabExcessVerticalSpace = true; >- gridData.horizontalSpan = 1; >- pathVariablesComposite.setLayoutData(gridData); >- >- Label pathVariablesLabel = new Label(pathVariablesComposite, SWT.LEFT); >- gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); >- gridData.grabExcessHorizontalSpace = true; >- gridData.grabExcessVerticalSpace = false; >- gridData.horizontalSpan = 2; >- gridData.verticalIndent = 20; >- pathVariablesLabel.setLayoutData(gridData); >- pathVariablesLabel.setText(EMFUIMessages.PathmapsPreferencePage_availablePathVariables); >- >- 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; >- 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)); >- add = new Button(buttonComposite, SWT.CENTER); >- add.setText(EMFUIMessages.PathmapsPreferencePage_addChevron); >- gridData = new GridData(GridData.FILL_HORIZONTAL); >- gridData.grabExcessHorizontalSpace = true; >- gridData.grabExcessVerticalSpace = false; >- gridData.horizontalSpan = 1; >- add.setLayoutData(gridData); >- Button addAll = new Button(buttonComposite, SWT.CENTER); >- addAll.setText(EMFUIMessages.PathmapsPreferencePage_addAllChevron); >- gridData = new GridData(GridData.FILL_HORIZONTAL); >- gridData.grabExcessHorizontalSpace = true; >- gridData.grabExcessVerticalSpace = false; >- addAll.setLayoutData(gridData); >- remove = new Button(buttonComposite,SWT.CENTER); >- remove.setText(EMFUIMessages.PathmapsPreferencePage_removeChevron); >- gridData = new GridData(GridData.FILL_HORIZONTAL); >- gridData.grabExcessHorizontalSpace = true; >- gridData.grabExcessVerticalSpace = false; >- gridData.horizontalSpan = 1; >- gridData.verticalIndent = 10; >- remove.setLayoutData(gridData); >- Button removeAll = new Button(buttonComposite, SWT.CENTER); >- removeAll.setText(EMFUIMessages.PathmapsPreferencePage_removeAllChevron); >- gridData = new GridData(GridData.FILL_HORIZONTAL); >- gridData.grabExcessHorizontalSpace = true; >- gridData.grabExcessVerticalSpace = false; >- gridData.horizontalSpan=1; >- removeAll.setLayoutData(gridData); >- >- gridData = new GridData(GridData.FILL_HORIZONTAL); >- gridData.grabExcessHorizontalSpace = false; >- gridData.grabExcessVerticalSpace = false; >- gridData.horizontalSpan = 1; >- buttonComposite.setLayoutData(gridData); >- >- Composite referencedPathVariablesComposite = new Composite(composite, SWT.NONE); >- referencedPathVariablesComposite.setLayout(new GridLayout(1, false)); >- gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); >- gridData.grabExcessHorizontalSpace = true; >- gridData.grabExcessVerticalSpace = true; >- gridData.horizontalSpan = 1; >- referencedPathVariablesComposite.setLayoutData(gridData); >- >- Label referencedPathVariablesLabel = new Label(referencedPathVariablesComposite, SWT.LEFT); >- gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); >- gridData.grabExcessHorizontalSpace = true; >- gridData.grabExcessVerticalSpace = false; >- gridData.horizontalSpan = 1; >- gridData.verticalIndent = 20; >- referencedPathVariablesLabel.setLayoutData(gridData); >- referencedPathVariablesLabel.setText(EMFUIMessages.PathmapsPreferencePage_pathVariablesUsedInModeling); >- >- 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; >- 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.getTable().addMouseTrackListener(new MouseTrackAdapter() { >- public void mouseHover(MouseEvent e) { >- TableItem item = pathVariables.getTable().getItem(new Point(e.x, e.y)); >- String tip = null; >- >- if (item != null) { >- String var = item.getText(0); >- tip = getValue(var, false); >- } >- >- pathVariables.getTable().setToolTipText(tip); >- }}); >- >- 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); >- } >- } >- } >- }); >- >- referencedPathVariables.getTable().addMouseTrackListener(new MouseTrackAdapter() { >- public void mouseHover(MouseEvent e) { >- TableItem item = referencedPathVariables.getTable().getItem( >- new Point(e.x, e.y)); >- String tip = null; >- >- if (item != null) { >- String var = item.getText(0); >- tip = getValue(var, true); >- } >- >- referencedPathVariables.getTable().setToolTipText(tip); >- }}); >- >- 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) { >- IStructuredSelection selection = >- (IStructuredSelection) pathVariables.getSelection(); >- >- for (Iterator iter = selection.iterator(); iter.hasNext();) { >- String name = (String) iter.next(); >- pathVariablesContent.remove(name); >- referencedPathVariablesContent.add(name); >- adjustScrollpanes(); >- } >- } >- >- public void widgetDefaultSelected(SelectionEvent e) { >- // No action is necessary >- } >- }); >- >- addAll.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- // No action necessary >- } >- >- public void widgetSelected(SelectionEvent e) { >- Object[] items = pathVariablesContent.getElements(null); >- >- for (int i=items.length - 1; i >= 0; i--) { >- if (validateAdditions(new StructuredSelection(items[i]), false)) { >- String name = (String) items[i]; >- pathVariablesContent.remove(name); >- referencedPathVariablesContent.add(name); >- adjustScrollpanes(); >- } >- } >- } >- }); >- >- remove.addSelectionListener(new SelectionListener() { >- public void widgetSelected(SelectionEvent e) { >- IStructuredSelection selection = >- (IStructuredSelection) referencedPathVariables.getSelection(); >- >- for (Iterator iter = selection.iterator(); iter.hasNext();) { >- String name = (String) iter.next(); >- referencedPathVariablesContent.remove(name); >- pathVariablesContent.add(name); >- adjustScrollpanes(); >- } >- } >- >- public void widgetDefaultSelected(SelectionEvent e) { >- // No action is necessary >- } >- }); >- >- removeAll.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- // No action is necessary >- } >- >- public void widgetSelected(SelectionEvent e) { >- Object[] items = referencedPathVariablesContent.getElements(null); >- >- for (int i=items.length - 1; i >= 0; i--) { >- if (validateRemovals(new StructuredSelection(items[i]), false)) { >- String name = (String) items[i]; >- referencedPathVariablesContent.remove(name); >- pathVariablesContent.add(name); >- adjustScrollpanes(); >- } >- } >- } >- }); >- >- initializeContents(); >- >- // In case of any changes to the path variables, we will refresh ourselves to show >- // the up-to-date information. >- pathVariableChangeListener = new IPathVariableChangeListener() { >- public void pathVariableChanged(IPathVariableChangeEvent event) { >- referencedPathVariables.getTable().getDisplay().asyncExec(new Runnable() { >- public void run() { >- if (!PathmapsPreferencePage.this.disposed) { >- performDefaults(); >- } >- } >- }); >- } >- }; >- ResourcesPlugin.getWorkspace().getPathVariableManager().addChangeListener(pathVariableChangeListener); >- >- disposed = false; >- >- applyDialogFont(composite); >- >- return composite; >- } >- >- 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 String getValue(String pathVariable, boolean includeRegistered) { >- String result = null; >- >- if (includeRegistered && PathmapManager.isRegisteredPathVariable(pathVariable)) { >- String path = PathmapManager.getRegisteredValue(pathVariable); >- >- if (path != null) { >- URI uri = URI.createURI(path); >- uri = CommonPlugin.resolve(uri); >- >- if (uri.isFile()) { >- path = uri.toFileString(); >- } else { >- path = uri.toString(); >- } >- >- result = path; >- } >- } else { >- IPathVariableManager pathVarMgr = >- ResourcesPlugin.getWorkspace().getPathVariableManager(); >- >- IPath path = pathVarMgr.getValue(pathVariable); >- >- if (path != null) { >- result = path.toOSString(); >- } >- } >- >- return result; >- } >- >- private boolean validateAdditions(IStructuredSelection selection, boolean showError) { >- if (selection.isEmpty()) >- return false; >- >- for (Iterator iter = selection.iterator(); iter.hasNext();) { >- String name = (String) iter.next(); >- >- if (!PathmapManager.isCompatiblePathVariable(name)) { >- if (showError) { >- setMessage(EMFUIMessages.PathmapsPreferencePage_incompatiblePathVariableErrorMessage,ERROR); >- } >- return false; >- } >- >- if (PathmapManager.isRegisteredPathVariable(name)) { >- if (showError) { >- setMessage(EMFUIMessages.PathmapsPreferencePage_registeredPathVariableErrorMessage,ERROR); >- } >- return false; >- } >- } >- return true; >- } >- >- private boolean validateRemovals(IStructuredSelection selection, boolean showError) { >- if (selection.isEmpty()) >- return false; >- >- for (Iterator iter = selection.iterator(); iter.hasNext();) { >- String name = (String) iter.next(); >- >- if (PathmapManager.isRegisteredPathVariable(name)) { >- if (showError) { >- setMessage(EMFUIMessages.PathmapsPreferencePage_registeredPathVariableErrorMessage,ERROR); >- } >- return false; >- } >- } >- return true; >- } >- >- private void initializeContents() { >- setMessage(null); >- add.setEnabled(true); >- remove.setEnabled(true); >- >- referencedPathVariables.setInput(new HashSet(PathmapManager.getAllPathVariables())); >- >- Set currentVariables = PathmapManager.getPathVariableReferences(); >- >- Set available = new HashSet(); >- String[] pathVariableNames = ResourcesPlugin.getWorkspace().getPathVariableManager().getPathVariableNames(); >- for (int i=0; i<pathVariableNames.length; i++) { >- if (!currentVariables.contains(pathVariableNames[i])) { >- available.add(pathVariableNames[i]); >- } >- } >- >- pathVariables.setInput(available); >- } >- >- public void init(IWorkbench workbench) { >- // No initialization is necessary. >- } >- >- protected void performDefaults() { >- initializeContents(); >- super.performDefaults(); >- } >- >- public boolean performOk() { >- Object[] nonReferencedPathVariables = pathVariablesContent.getElements(null); >- for (int i=0; i<nonReferencedPathVariables.length; i++) { >- String variableName = (String) nonReferencedPathVariables[i]; >- PathmapManager.removePathVariableReference(variableName); >- } >- >- Set currentVariables = PathmapManager.getAllPathVariables(); >- Object[] variablesToReference = referencedPathVariablesContent.getElements(null); >- for (int i=0; i<variablesToReference.length; i++) { >- String variableName = (String) variablesToReference[i]; >- >- if (!currentVariables.contains(variableName)) { >- PathmapManager.addPathVariableReference(variableName); >- } >- } >- >- PathmapManager.updatePreferenceStore(); >- >- return true; >- } >- >- public void dispose() { >- disposed = true; >- if (pathVariableChangeListener != null) { >- ResourcesPlugin.getWorkspace().getPathVariableManager().removeChangeListener(pathVariableChangeListener); >- pathVariableChangeListener = null; >- } >- super.dispose(); >- } >- >- private static class StringsContentProvider implements IStructuredContentProvider { >- private Set strings; >- private TableViewer table; >- >- StringsContentProvider() { >- strings = new HashSet(); >- } >- >- void add(String string) { >- if (!strings.contains(string)) { >- strings.add(string); >- table.add(string); >- } >- } >- >- void remove(String string) { >- if (strings.contains(string)) { >- strings.remove(string); >- table.remove(string); >- } >- } >- >- public Object[] getElements(Object inputElement) { >- return strings.toArray(); >- } >- >- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >- strings = (Set) newInput; >- table = (TableViewer) viewer; >- } >- >- public void dispose() { >- // nothing to clean up >- } >- } >- >- private static class StringsLabelProvider implements ITableLabelProvider, IColorProvider { >- private final boolean isReferencedPathVariables; >- >+ gridData = new GridData(GridData.FILL_HORIZONTAL >+ | GridData.FILL_VERTICAL); >+ gridData.grabExcessHorizontalSpace = true; >+ gridData.grabExcessVerticalSpace = false; >+ gridData.horizontalSpan = 2; >+ pathVariablesArea.getControl().setLayoutData(gridData); >+ >+ Label pathVariablesLabel = new Label(composite, SWT.LEFT); >+ gridData = new GridData(GridData.FILL_HORIZONTAL >+ | GridData.FILL_VERTICAL); >+ gridData.grabExcessHorizontalSpace = true; >+ gridData.grabExcessVerticalSpace = false; >+ gridData.horizontalSpan = 2; >+ gridData.verticalIndent = 20; >+ pathVariablesLabel.setLayoutData(gridData); >+ pathVariablesLabel >+ .setText(EMFUIMessages.PathmapsPreferencePage_availablePathVariables); >+ >+ pathVariablesScroll = new ScrolledComposite(composite, 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; >+ pathVariablesScroll.setLayoutData(gridData); >+ >+ pathVariables = CheckboxTableViewer.newCheckList(pathVariablesScroll, >+ SWT.MULTI); >+ pathVariablesScroll.setContent(pathVariables.getTable()); >+ >+ pathVariablesContent = new PathVariableContentProvider(); >+ pathVariables.setContentProvider(pathVariablesContent); >+ pathVariables.setLabelProvider(new PathVariableLabelProvider()); >+ pathVariables.setComparator(new PathVariableViewerComparator()); >+ >+ Composite buttonComposite = new Composite(composite, SWT.NONE); >+ buttonComposite.setLayout(new GridLayout(1, false)); >+ gridData = new GridData(GridData.FILL_HORIZONTAL); >+ gridData.grabExcessHorizontalSpace = false; >+ gridData.grabExcessVerticalSpace = false; >+ gridData.horizontalSpan = 1; >+ gridData.verticalAlignment = GridData.BEGINNING; >+ buttonComposite.setLayoutData(gridData); >+ >+ newVariable = new Button(buttonComposite, SWT.CENTER); >+ newVariable.setText(EMFUIMessages.PathmapsPreferencePage_newVariable); >+ setButtonLayoutData(newVariable); >+ >+ editVariable = new Button(buttonComposite, SWT.CENTER); >+ editVariable.setText(EMFUIMessages.PathmapsPreferencePage_editVariable); >+ setButtonLayoutData(editVariable); >+ >+ removeVariable = new Button(buttonComposite, SWT.CENTER); >+ removeVariable >+ .setText(EMFUIMessages.PathmapsPreferencePage_removeVariable); >+ setButtonLayoutData(removeVariable); >+ >+ pathVariables >+ .addSelectionChangedListener(new ISelectionChangedListener() { >+ >+ public void selectionChanged(SelectionChangedEvent event) { >+ pathVariableSelected(event.getSelection()); >+ } >+ }); >+ >+ pathVariables.addCheckStateListener(new ICheckStateListener() { >+ >+ public void checkStateChanged(CheckStateChangedEvent event) { >+ pathVariableChecked(event, (PathVariableEntry) event >+ .getElement()); >+ } >+ }); >+ >+ newVariable.addSelectionListener(new SelectionAdapter() { >+ >+ public void widgetSelected(SelectionEvent e) { >+ addPathVariable(); >+ } >+ }); >+ >+ editVariable.addSelectionListener(new SelectionAdapter() { >+ >+ public void widgetSelected(SelectionEvent e) { >+ editPathVariable(pathVariables.getSelection()); >+ } >+ }); >+ >+ removeVariable.addSelectionListener(new SelectionAdapter() { >+ >+ public void widgetSelected(SelectionEvent e) { >+ removePathVariable(pathVariables.getSelection()); >+ } >+ }); >+ >+ initializeContents(); >+ >+ applyDialogFont(composite); >+ >+ pathVariableSelected(pathVariables.getSelection()); >+ >+ return composite; >+ } >+ >+ /** >+ * Responds to the user's gesture to either check or uncheck the specified >+ * <code>entry</code> in the path variables list. This may, according to >+ * the status of the path variable entry, result in the user's change being >+ * reverted (e.g., in the case of attempting to uncheck a variable >+ * registered on the extension point). This works around the inability in >+ * SWT to disable the checkbox of an item in a check-table (see <a >+ * href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=76509">bug 76509</a> >+ * for details). >+ * >+ * @param event >+ * the (un)check event >+ * @param entry >+ * the path variable entry that was (un)checked >+ */ >+ private void pathVariableChecked(CheckStateChangedEvent event, >+ PathVariableEntry entry) { >+ if (event.getChecked()) { >+ // validate the check >+ if (validateSelection(entry, false)) { >+ entry.setSelected(true); >+ } else { >+ event.getCheckable().setChecked(entry, false); >+ } >+ } else { >+ // validate the uncheck >+ if (validateDeselection(entry, false)) { >+ entry.setSelected(false); >+ } else { >+ event.getCheckable().setChecked(entry, true); >+ } >+ } >+ } >+ >+ /** >+ * Handles the selection of zero or more path variables in the list, >+ * updating the enablement state of the "Edit..." and "Remove" buttons. >+ * >+ * @param selection >+ * the new path variables list selection >+ */ >+ private void pathVariableSelected(ISelection selection) { >+ IStructuredSelection ssel = (IStructuredSelection) selection; >+ >+ editVariable.setEnabled(validateEdit(ssel, false)); >+ removeVariable.setEnabled(validateRemove(ssel, false)); >+ } >+ >+ /** >+ * Updates the map of pending path variable changes to indicate that the >+ * specified variable has been added by the user. >+ * >+ * @param variableName >+ * the name of the added variable >+ */ >+ private void markAdded(String variableName) { >+ Object currentChange = variableChanges.get(variableName); >+ >+ if (currentChange == removedToken) { >+ // if we previously removed this variable's value, then it will >+ // appear to be a change when we sync on apply >+ variableChanges.put(variableName, changedToken); >+ } else if (currentChange != changedToken) { >+ // shouldn't have been a "changed" if we thought we were adding >+ variableChanges.put(variableName, addedToken); >+ } >+ } >+ >+ /** >+ * Queries whether the specified path variable has an add change pending, to >+ * be applied when the OK/Apply button is pressed. >+ * >+ * @param variableName >+ * the path variable name >+ * @return <code>true</code> if the variable has a pending change that is >+ * an add; <code>false</code>, otherwise >+ */ >+ boolean isAdded(String variableName) { >+ return variableChanges.get(variableName) == addedToken; >+ } >+ >+ /** >+ * Updates the map of pending path variable changes to indicate that the >+ * specified variable has been removed by the user. >+ * >+ * @param variableName >+ * the name of the removed variable >+ */ >+ private void markRemoved(String variableName) { >+ Object currentChange = variableChanges.get(variableName); >+ >+ if (currentChange == addedToken) { >+ // it was added since the last apply? Just forget about it, then >+ variableChanges.remove(variableName); >+ } else { >+ variableChanges.put(variableName, removedToken); >+ } >+ } >+ >+ /** >+ * Queries whether the specified path variable has a remove change pending, >+ * to be applied when the OK/Apply button is pressed. >+ * >+ * @param variableName >+ * the path variable name >+ * @return <code>true</code> if the variable has a pending change that is >+ * a removal; <code>false</code>, otherwise >+ */ >+ boolean isRemoved(String variableName) { >+ return variableChanges.get(variableName) == removedToken; >+ } >+ >+ /** >+ * Updates the map of pending path variable changes to indicate that the >+ * specified variable's value has been changed by the user. >+ * >+ * @param variableName >+ * the name of the changed variable >+ */ >+ private void markChanged(String variableName) { >+ Object currentChange = variableChanges.get(variableName); >+ >+ if (currentChange == addedToken) { >+ // do nothing in this case. If it was added, changing it doesn't >+ // change the fact that it's a new variable >+ } else { >+ variableChanges.put(variableName, changedToken); >+ } >+ } >+ >+ /** >+ * Queries whether the specified path variable has a change of value >+ * pending, to be applied when the OK/Apply button is pressed. >+ * >+ * @param variableName >+ * the path variable name >+ * @return <code>true</code> if the variable has a pending change that is >+ * a value change; <code>false</code>, otherwise >+ */ >+ boolean isChanged(String variableName) { >+ return variableChanges.get(variableName) == changedToken; >+ } >+ >+ /** >+ * Queries whether the current pending path variables (not yet applied to >+ * the workspace and GMF path map manager) has a variable referencing the >+ * specified location. Note that this does not consider path variables that >+ * are pending removal or others that are currently defined in the workspace >+ * and/or GMF that are not visible. >+ * >+ * @param location >+ * a location >+ * @return <code>true</code> if any of the path variables showing in the >+ * preference page has the specified location; <code>false</code>, >+ * otherwise >+ */ >+ boolean isLocationDefined(IPath location) { >+ for (Iterator iter = pathVariablesContent.entries.iterator(); iter >+ .hasNext();) { >+ if (location.equals(((PathVariableEntry) iter.next()) >+ .getLocationPath())) { >+ return true; >+ } >+ } >+ >+ return false; >+ } >+ >+ /** >+ * Handles the pushing of the "New..." button, to create a new path map >+ * variable. >+ */ >+ private void addPathVariable() { >+ NewPathVariableDialog dlg = NewPathVariableDialog.openNew(this); >+ if (dlg != null) { >+ String name = dlg.getVariableName(); >+ IPath location = dlg.getVariableLocation(); >+ >+ // prepare data for synchronization on apply >+ markAdded(name); >+ >+ // by default, check the variable (if the user created it in this >+ // pref page, assume that it should be used for GMF modeling) >+ PathVariableEntry entry = new PathVariableEntry(name, location); >+ entry.setSelected(true); >+ pathVariablesContent.add(entry); >+ pathVariables.setChecked(entry, true); >+ >+ // select the new path variable >+ pathVariables.setSelection(new StructuredSelection(entry)); >+ } >+ } >+ >+ /** >+ * Handles the pushing of the "Edit..." button, to edit the path variable >+ * contained in the specified <code>selection</code>. >+ * >+ * @param selection >+ * the current selection in the path variables list (should >+ * contain a single {@link PathVariableEntry}) >+ */ >+ private void editPathVariable(ISelection selection) { >+ PathVariableEntry entry = null; >+ >+ if (selection instanceof IStructuredSelection) { >+ IStructuredSelection ssel = (IStructuredSelection) selection; >+ >+ if (!ssel.isEmpty()) { >+ entry = (PathVariableEntry) ssel.getFirstElement(); >+ } >+ } >+ >+ if (entry != null) { >+ String oldName = entry.getName(); >+ NewPathVariableDialog dlg = NewPathVariableDialog.openEdit(this, >+ oldName, entry.getLocation()); >+ >+ if (dlg != null) { >+ String newName = dlg.getVariableName(); >+ IPath newLocation = dlg.getVariableLocation(); >+ boolean nameChanged = !oldName.equals(newName); >+ >+ if (nameChanged) { >+ // changing the name is like removing the old name >+ // and adding the new name >+ >+ // prepare data for synchronization on apply >+ markAdded(newName); >+ markRemoved(oldName); >+ } else { >+ // prepare data for synchronization on apply >+ markChanged(oldName); >+ } >+ >+ entry.setName(newName); >+ entry.setLocation(newLocation); >+ >+ pathVariables.update(entry, >+ nameChanged ? new String[] {NAME_ATTRIBUTE} >+ : null); >+ } >+ } >+ } >+ >+ /** >+ * Handles the pushing of the "Remove" button, to remove the path >+ * variable(s) contained in the specified <code>selection</code>. >+ * >+ * @param selection >+ * the current selection in the path variables list (should >+ * contain one or more {@link PathVariableEntry}s of which none >+ * is registered on the extension point) >+ */ >+ private void removePathVariable(ISelection selection) { >+ Iterator entries = null; >+ >+ if (selection instanceof IStructuredSelection) { >+ IStructuredSelection ssel = (IStructuredSelection) selection; >+ >+ if (!ssel.isEmpty()) { >+ entries = ssel.iterator(); >+ } >+ } >+ >+ if (entries != null) { >+ while (entries.hasNext()) { >+ PathVariableEntry entry = (PathVariableEntry) entries.next(); >+ String name = entry.getName(); >+ >+ // prepare data for synchronization on apply >+ markRemoved(name); >+ >+ pathVariablesContent.remove(entry); >+ } >+ } >+ } >+ >+ /** >+ * Validates an attempt to check a previously unchecked path variable in the >+ * list, optionally showing an error explaining the reason why this is not >+ * permitted. >+ * >+ * @param entry >+ * a path variable that the user attempted to check >+ * @param showError >+ * whether to show any potential error message in the title area >+ * @return whether the checking of this variable is permitted >+ */ >+ private boolean validateSelection(PathVariableEntry entry, boolean showError) { >+ String name = entry.getName(); >+ >+ if (!PathmapManager.isCompatiblePathVariable(name)) { >+ if (showError) { >+ setMessage( >+ EMFUIMessages.PathmapsPreferencePage_incompatiblePathVariableErrorMessage, >+ ERROR); >+ } >+ return false; >+ } >+ >+ if (PathmapManager.isRegisteredPathVariable(name)) { >+ if (showError) { >+ setMessage( >+ EMFUIMessages.PathmapsPreferencePage_registeredPathVariableErrorMessage, >+ ERROR); >+ } >+ return false; >+ } >+ >+ return true; >+ } >+ >+ /** >+ * Validates an attempt to uncheck a previously checked path variable in the >+ * list, optionally showing an error explaining the reason why this is not >+ * permitted. >+ * >+ * @param entry >+ * a path variable that the user attempted to uncheck >+ * @param showError >+ * whether to show any potential error message in the title area >+ * @return whether the unchecking of this variable is permitted >+ */ >+ private boolean validateDeselection(PathVariableEntry entry, >+ boolean showError) { >+ if (entry.isRequired()) { >+ if (showError) { >+ setMessage( >+ EMFUIMessages.PathmapsPreferencePage_registeredPathVariableErrorMessage, >+ ERROR); >+ } >+ return false; >+ } >+ >+ return true; >+ } >+ >+ /** >+ * Queries whether it is permitted to edit the specified >+ * <code>selection</code> of path variables. Editing is only permitted for >+ * a single selection that is not a registered path variable. >+ * >+ * @param selection >+ * the current selection in the path variables list >+ * @param showError >+ * whether to show any potential error message in the title area >+ * @return whether the editing of this selection is permitted >+ */ >+ private boolean validateEdit(IStructuredSelection selection, >+ boolean showError) { >+ if (selection.isEmpty() || (selection.size() > 1)) { >+ return false; >+ } >+ >+ String name = ((PathVariableEntry) selection.getFirstElement()) >+ .getName(); >+ >+ if (PathmapManager.isRegisteredPathVariable(name)) { >+ if (showError) { >+ setMessage( >+ EMFUIMessages.PathmapsPreferencePage_registeredPathVariableErrorMessage, >+ ERROR); >+ } >+ >+ return false; >+ } >+ >+ return true; >+ } >+ >+ /** >+ * Queries whether it is permitted to remove the specified >+ * <code>selection</code> of path variables. Removal is only permitted >+ * when the selection is not empty and does not contain any registered path >+ * variable. >+ * >+ * @param selection >+ * the current selection in the path variables list >+ * @param showError >+ * whether to show any potential error message in the title area >+ * @return whether the editing of this selection is permitted >+ */ >+ private boolean validateRemove(IStructuredSelection selection, >+ boolean showError) { >+ if (selection.isEmpty()) { >+ return false; >+ } >+ >+ for (Iterator iter = selection.iterator(); iter.hasNext();) { >+ String name = ((PathVariableEntry) iter.next()).getName(); >+ >+ if (PathmapManager.isRegisteredPathVariable(name)) { >+ if (showError) { >+ setMessage( >+ EMFUIMessages.PathmapsPreferencePage_registeredPathVariableErrorMessage, >+ ERROR); >+ } >+ >+ return false; >+ } >+ } >+ >+ return true; >+ } >+ >+ /** >+ * Loads the contents of the Path Variables list, additionally setting the >+ * check state of each variable. >+ */ >+ private void initializeContents() { >+ setMessage(null); >+ >+ variableChanges.clear(); >+ >+ Set currentVariables = PathmapManager.getPathVariableReferences(); >+ >+ Set allVariables = new HashSet(); >+ Set checkedVariables = new HashSet(); >+ >+ Set pathVariableNames = new HashSet(); >+ pathVariableNames.addAll(Arrays.asList(pathVariableManager >+ .getPathVariableNames())); >+ pathVariableNames.addAll(PathmapManager.getAllPathVariables()); >+ >+ for (Iterator iter = pathVariableNames.iterator(); iter.hasNext();) { >+ String name = (String) iter.next(); >+ PathVariableEntry entry; >+ >+ if (PathmapManager.isRegisteredPathVariable(name)) { >+ String value = PathmapManager.getRegisteredValue(name); >+ >+ try { >+ URI uri = URI.createURI(value); >+ >+ if (uri.isFile()) { >+ // show the user a familiar file system path instead >+ // of a URI >+ value = uri.toFileString(); >+ } >+ } catch (RuntimeException e) { >+ // the value is not a valid URI. Nothing for us to >+ // do; that is a problem for the plug-in developer >+ // who registered this path map. We'll show the >+ // value as is >+ } >+ >+ entry = new PathVariableEntry(name, value); >+ checkedVariables.add(entry); >+ allVariables.add(entry); >+ } else if (PathmapManager.isCompatiblePathVariable(name)) { >+ >+ entry = new PathVariableEntry(name, pathVariableManager >+ .getValue(name)); >+ >+ if (currentVariables.contains(entry.getName())) { >+ checkedVariables.add(entry); >+ entry.setSelected(true); >+ } >+ >+ allVariables.add(entry); >+ } >+ } >+ >+ pathVariables.setInput(allVariables); >+ pathVariables.setCheckedElements(checkedVariables.toArray()); >+ } >+ >+ public void init(IWorkbench workbench) { >+ // No initialization is necessary. >+ } >+ >+ protected void performDefaults() { >+ initializeContents(); >+ super.performDefaults(); >+ } >+ >+ /** >+ * Applies the current check state of every path variable to the GMF >+ * {@link PathmapManager}'s list of path variable references and saves the >+ * preference store. >+ */ >+ public boolean performOk() { >+ Set currentVariables = PathmapManager.getPathVariableReferences(); >+ >+ try { >+ // first, process the removed workspace path variables >+ for (Iterator iter = variableChanges.keySet().iterator(); iter >+ .hasNext();) { >+ String name = (String) iter.next(); >+ >+ if (isRemoved(name)) { >+ if (pathVariableManager.isDefined(name)) { >+ pathVariableManager.setValue(name, null); >+ } >+ >+ PathmapManager.removePathVariableReference(name); >+ >+ iter.remove(); // successfully processed this change >+ } >+ } >+ >+ // next, process the current set of path variable references to >+ // add/remove them according to the user's preferences >+ Object[] variables = pathVariablesContent.getElements(null); >+ for (int i = 0; i < variables.length; i++) { >+ PathVariableEntry entry = (PathVariableEntry) variables[i]; >+ String name = entry.getName(); >+ >+ if (isChanged(name) || isAdded(name) >+ && !pathVariableManager.isDefined(name)) { >+ // set the workspace path variable's new value, now >+ pathVariableManager.setValue(name, new Path(entry >+ .getLocation())); >+ >+ // successfully processed this change >+ variableChanges.remove(name); >+ } >+ >+ if (entry.isSelected() && !currentVariables.contains(name)) { >+ PathmapManager.addPathVariableReference(name); >+ } else if (!entry.isSelected() >+ && currentVariables.contains(name)) { >+ PathmapManager.removePathVariableReference(name); >+ } >+ } >+ >+ PathmapManager.updatePreferenceStore(); >+ >+ return true; >+ } catch (CoreException e) { >+ ErrorDialog.openError(getShell(), >+ EMFUIMessages.PathmapsPreferencePage_promptTitle, >+ EMFUIMessages.PathmapsPreferencePage_updateFailed, e >+ .getStatus()); >+ return false; >+ } >+ } >+ >+ /** >+ * A content provider for the Path Variables list. >+ */ >+ private static class PathVariableContentProvider >+ implements IStructuredContentProvider { >+ >+ private Set entries; >+ >+ private TableViewer table; >+ >+ PathVariableContentProvider() { >+ entries = new HashSet(); >+ } >+ >+ /** >+ * Adds a path variable to the list. >+ * >+ * @param entry >+ * the new path variable >+ */ >+ void add(PathVariableEntry entry) { >+ if (!entries.contains(entry)) { >+ entries.add(entry); >+ table.add(entry); >+ } >+ } >+ >+ /** >+ * Removes a path variable from the list. >+ * >+ * @param entry >+ * the path variable to remove >+ */ >+ void remove(PathVariableEntry entry) { >+ if (entries.contains(entry)) { >+ entries.remove(entry); >+ table.remove(entry); >+ } >+ } >+ >+ public Object[] getElements(Object inputElement) { >+ return entries.toArray(); >+ } >+ >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ entries = (Set) newInput; >+ table = (TableViewer) viewer; >+ } >+ >+ public void dispose() { >+ // nothing to clean up >+ } >+ } >+ >+ /** >+ * A label provider for the Path Variables list. >+ */ >+ private static class PathVariableLabelProvider >+ implements ITableLabelProvider, IColorProvider { >+ > private Image lockImage = null; >- >- StringsLabelProvider() { >- this(false); >- } >- >- StringsLabelProvider(boolean isReferencedPathVariables) { >- this.isReferencedPathVariables = isReferencedPathVariables; >- } >- >- public Image getColumnImage(Object element, int columnIndex) { >- if (isReferencedPathVariables && PathmapManager.isRegisteredPathVariable((String) element)) { >+ >+ PathVariableLabelProvider() { >+ super(); >+ } >+ >+ /** >+ * Shows a lock icon for registered path variables. >+ */ >+ public Image getColumnImage(Object element, int columnIndex) { >+ PathVariableEntry entry = (PathVariableEntry) element; >+ String name = entry.getName(); >+ >+ if (PathmapManager.isRegisteredPathVariable(name)) { > return getLockImage(); >+ } else if (!isDirectory(entry.getLocation())) { >+ return MslUIPlugin.getDefault().getWorkbench() >+ .getSharedImages() >+ .getImage(ISharedImages.IMG_OBJS_WARN_TSK); > } >- >- return null; >- } >- >+ >+ return null; >+ } >+ >+ /** >+ * Queries whether the specified location references a directory that >+ * exists. >+ * >+ * @param location >+ * a location >+ * @return <code>true</code> if the location exists in the filesystem >+ * and is a directory >+ */ >+ private boolean isDirectory(String location) { >+ File file = new File(location); >+ >+ return file.exists() && file.isDirectory(); >+ } >+ >+ /** >+ * Obtains the lazily-initialized lock image. >+ * >+ * @return the lock image >+ */ > private Image getLockImage() { > if (lockImage == null) { >- lockImage = MslUIPlugin.imageDescriptorFromPlugin( >- MslUIPlugin.getPluginId(), "/icons/full/lock.gif").createImage(); //$NON-NLS-1$ >+ lockImage = MslUIPlugin >+ .imageDescriptorFromPlugin(MslUIPlugin.getPluginId(), >+ "/icons/full/lock.gif").createImage(); //$NON-NLS-1$ > } >- >+ > return lockImage; > } > >- public String getColumnText(Object element, int columnIndex) { >- return (columnIndex == 0) ? (String) element : null; >- } >- >- public void dispose() { >- if (lockImage != null) { >- lockImage.dispose(); >+ /** >+ * Path variables are displayed in the same way as in the Linked >+ * Resources preference page. >+ */ >+ public String getColumnText(Object element, int columnIndex) { >+ if (columnIndex != 0) { >+ return null; >+ } >+ >+ PathVariableEntry entry = (PathVariableEntry) element; >+ return NLS.bind( >+ EMFUIMessages.PathmapsPreferencePage_variablePattern, entry >+ .getName(), entry.getLocation()); >+ } >+ >+ public void dispose() { >+ if (lockImage != null) { >+ lockImage.dispose(); > lockImage = null; > } >- } >+ } >+ >+ public boolean isLabelProperty(Object element, String property) { >+ return false; >+ } >+ >+ public void addListener(ILabelProviderListener listener) { >+ // not using listeners >+ } >+ >+ public void removeListener(ILabelProviderListener listener) { >+ // not using listeners >+ } >+ >+ public Color getBackground(Object element) { >+ return null; >+ } >+ >+ public Color getForeground(Object element) { >+ return null; >+ } >+ } >+ >+ /** >+ * A sorter for the Path Variables list. All registered path maps sort to >+ * the bottom of the list to keep them out of the user's way. >+ */ >+ private static class PathVariableViewerComparator >+ extends ViewerComparator { >+ >+ PathVariableViewerComparator() { >+ super(); >+ } >+ >+ /** >+ * We sort by <code>name</code>. >+ */ >+ public boolean isSorterProperty(Object element, String property) { >+ return NAME_ATTRIBUTE.equals(property); >+ } >+ >+ /** >+ * Registered variables are in a higher category than user variables. >+ */ >+ public int category(Object element) { >+ // sort statically-registered variables to the end of the list >+ return PathmapManager >+ .isRegisteredPathVariable(((PathVariableEntry) element) >+ .getName()) ? 1 >+ : 0; >+ } >+ } >+ >+ /** >+ * Data model for a path variable in the Path Variables list. >+ */ >+ private static final class PathVariableEntry { >+ >+ private String name; >+ >+ private String location; >+ >+ private IPath locationPath; >+ >+ private final boolean required; >+ >+ private boolean selected; >+ >+ /** >+ * Initializes a user-defined path variable with the name and location >+ * path. >+ * >+ * @param name >+ * the variable name >+ * @param location >+ * the location >+ */ >+ PathVariableEntry(String name, IPath location) { >+ this(name, location.toPortableString(), false); >+ >+ this.locationPath = location; >+ } >+ >+ /** >+ * Initializes a registered path variable with the name and location >+ * derived from the URI. >+ * >+ * @param name >+ * the variable name >+ * @param location >+ * the location URI >+ */ >+ PathVariableEntry(String name, String location) { >+ this(name, location, true); >+ } >+ >+ private PathVariableEntry(String name, String location, boolean required) { >+ this.name = name; >+ this.location = location; >+ this.required = required; >+ selected = required; >+ } >+ >+ /** >+ * Queries whether this path variable is required (a registered path >+ * variable that the user cannot edit, remove, or uncheck). >+ * >+ * @return whether I am required >+ */ >+ boolean isRequired() { >+ return required; >+ } >+ >+ /** >+ * Obtains the path variable name. >+ * >+ * @return my name >+ */ >+ String getName() { >+ return name; >+ } >+ >+ /** >+ * Sets the path variable name, if it is editable. >+ * >+ * @param name >+ * the new name >+ */ >+ void setName(String name) { >+ if (!isRequired()) { >+ this.name = name; >+ } >+ } >+ >+ /** >+ * Obtains the path variable location. >+ * >+ * @return my location >+ */ >+ String getLocation() { >+ return location; >+ } > >- public boolean isLabelProperty(Object element, String property) { >- return false; >- } >- >- public void addListener(ILabelProviderListener listener) { >- // not using listeners >- } >- >- public void removeListener(ILabelProviderListener listener) { >- // not using listeners >- } >- >- public Color getBackground(Object element) { >- return null; >- } >- >- public Color getForeground(Object element) { >- return null; >- } >- } >- >- private static class StringsViewerComparator extends ViewerComparator { >- StringsViewerComparator() { >- super(); >- } >- >- public int category(Object element) { >- // sort statically-registered variables to the end of the list >- return PathmapManager.isRegisteredPathVariable((String) element)? 1 : 0; >- } >- } >+ /** >+ * Obtains the path variable location, as an {@link IPath}. >+ * >+ * @return my location >+ */ >+ IPath getLocationPath() { >+ return locationPath; >+ } >+ >+ /** >+ * Sets the path variable name, if it is editable. >+ * >+ * @param location >+ * the new location >+ */ >+ void setLocation(IPath location) { >+ if (!isRequired()) { >+ this.locationPath = location; >+ this.location = location.toPortableString(); >+ } >+ } >+ >+ /** >+ * Queries whether the path variable is checked. Required (registered) >+ * path variables are always checked. >+ * >+ * @return whether I am checked >+ */ >+ boolean isSelected() { >+ return selected; >+ } >+ >+ /** >+ * Sets whether the path variable is checked, if it is not registered. >+ * >+ * @param selected >+ * whether I am checked >+ */ >+ void setSelected(boolean selected) { >+ if (!isRequired()) { >+ this.selected = selected; >+ } >+ } >+ >+ /** >+ * Displays path variable's debug string. >+ */ >+ public String toString() { >+ return getName() + " - " + getLocation(); //$NON-NLS-1$ >+ } >+ } > } >Index: src/org/eclipse/gmf/runtime/emf/ui/preferences/NewPathVariableDialog.java >=================================================================== >RCS file: src/org/eclipse/gmf/runtime/emf/ui/preferences/NewPathVariableDialog.java >diff -N src/org/eclipse/gmf/runtime/emf/ui/preferences/NewPathVariableDialog.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/runtime/emf/ui/preferences/NewPathVariableDialog.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,419 @@ >+/** >+ * <copyright> >+ * >+ * Copyright (c) 2007 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ * >+ * </copyright> >+ * >+ * $Id$ >+ */ >+package org.eclipse.gmf.runtime.emf.ui.preferences; >+ >+import java.io.File; >+ >+import org.eclipse.core.resources.IPathVariableManager; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.gmf.runtime.emf.core.internal.resources.PathmapManager; >+import org.eclipse.gmf.runtime.emf.ui.internal.MslUIPlugin; >+import org.eclipse.gmf.runtime.emf.ui.internal.l10n.EMFUIMessages; >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.jface.dialogs.IMessageProvider; >+import org.eclipse.jface.dialogs.TitleAreaDialog; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.ModifyEvent; >+import org.eclipse.swt.events.ModifyListener; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+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.DirectoryDialog; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Text; >+ >+/** >+ * Modal dialog for manipulation of path variables for modeling pathmaps. This >+ * dialog supports both creation of new path variables, using the >+ * {@link #openNew(Shell)} method, and editing of existing path variables, using >+ * the {@link #openEdit(Shell, String, String)} method. In either case, if the >+ * user successfully closes the dialog (i.e., hits the OK button), then the name >+ * and location of the variable are accessed via the {@link #getVariableName()} >+ * and {@link #getVariableLocation()} methods, respectively. >+ * <p> >+ * Note that this dialog intentionally differs from that utilized by the Linked >+ * Resources preference page because GMF's pathmaps apply more constraints to >+ * path variables, in particular that: >+ * </p> >+ * <ul> >+ * <li>a pathmap variable name must be a valid URI segment, because it is used >+ * as is in <tt>pathmap://</tt> URIs</li> >+ * <li>a pathmap variable must reference a folder, not a file</li> >+ * </ul> >+ * >+ * @author Christian W. Damus (cdamus) >+ */ >+class NewPathVariableDialog >+ extends TitleAreaDialog { >+ >+ private String variableName; >+ >+ private IPath variableLocation; >+ >+ private Text nameText; >+ >+ private Text locationText; >+ >+ private String initialName; >+ >+ private String initialLocation; >+ >+ private final IPathVariableManager pathMgr; >+ >+ private final String plainMsg; >+ >+ private final PathmapsPreferencePage page; >+ >+ /** >+ * Not instantiable by clients. >+ * >+ * @param page >+ * the path maps preference page that I serve >+ * @param name >+ * the current name of the variable to be edited, or >+ * <code>null</code> if creating a new path variable >+ * @param location >+ * the current location of the variable to be edited, or >+ * <code>null</code> if creating a new path variable >+ */ >+ private NewPathVariableDialog(PathmapsPreferencePage page, String name, >+ String location) { >+ super(page.getShell()); >+ >+ this.page = page; >+ >+ this.initialName = name; >+ this.initialLocation = location; >+ >+ if (name != null) { >+ // edit mode >+ plainMsg = EMFUIMessages.PathVariableDialog_editMessage; >+ } else { >+ // new mode >+ plainMsg = EMFUIMessages.PathVariableDialog_newMessage; >+ } >+ >+ pathMgr = ResourcesPlugin.getWorkspace().getPathVariableManager(); >+ } >+ >+ /** >+ * Opens the path-variable editing dialog in creation mode, to create a new >+ * path variable. >+ * >+ * @param page >+ * the path maps preference page that the dialog serves >+ * @return the dialog instance, from which the path variable data can be >+ * extracted, if the user closed it with the "OK" button; >+ * <code>null</code>, otherwise (i.e., if the user canceled) >+ */ >+ public static NewPathVariableDialog openNew(PathmapsPreferencePage page) { >+ NewPathVariableDialog dlg = new NewPathVariableDialog(page, null, null); >+ >+ return (dlg.open() == IDialogConstants.OK_ID) ? dlg >+ : null; >+ } >+ >+ /** >+ * Opens the path-variable editing dialog in edit mode, to modify an >+ * existing path variable. Clients must account for the possibility that the >+ * returned variable name may differ from the specified <code>name</code>, >+ * because users may rename variables. >+ * >+ * @param page >+ * the path maps preference page that the dialog serves >+ * @return the dialog instance, from which the path variable data can be >+ * extracted, if the user closed it with the "OK" button; >+ * <code>null</code>, otherwise (i.e., if the user canceled) >+ */ >+ public static NewPathVariableDialog openEdit(PathmapsPreferencePage page, >+ String name, String location) { >+ NewPathVariableDialog dlg = new NewPathVariableDialog(page, name, >+ location); >+ >+ return (dlg.open() == IDialogConstants.OK_ID) ? dlg >+ : null; >+ } >+ >+ /** >+ * Sets the dialog's window title according to whether it is in creation or >+ * edit mode. >+ */ >+ protected void configureShell(Shell newShell) { >+ super.configureShell(newShell); >+ >+ if (initialName != null) { >+ // edit mode >+ newShell.setText(EMFUIMessages.PathVariableDialog_editTitle); >+ } else { >+ // new mode >+ newShell.setText(EMFUIMessages.PathVariableDialog_newTitle); >+ } >+ } >+ >+ protected Control createDialogArea(Composite parent) { >+ Composite result = (Composite) super.createDialogArea(parent); >+ >+ initializeDialogUnits(result); >+ >+ Composite composite = new Composite(result, SWT.NONE); >+ composite.setLayout(new GridLayout(3, false)); >+ GridData data = null; >+ data = new GridData(GridData.FILL_BOTH); >+ data.grabExcessHorizontalSpace = true; >+ data.grabExcessHorizontalSpace = true; >+ data.horizontalIndent = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); >+ data.verticalIndent = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); >+ composite.setLayoutData(data); >+ >+ Label label = new Label(composite, SWT.LEFT); >+ label.setText(EMFUIMessages.PathVariableDialog_nameLabel); >+ data = new GridData(SWT.BEGINNING); >+ label.setLayoutData(data); >+ >+ nameText = new Text(composite, SWT.BORDER); >+ data = new GridData(GridData.FILL_HORIZONTAL); >+ data.grabExcessHorizontalSpace = true; >+ nameText.setLayoutData(data); >+ if (initialName != null) { >+ nameText.setText(initialName); >+ } >+ >+ // blank to occupy the upper-right corner >+ new Label(composite, SWT.None); >+ >+ label = new Label(composite, SWT.NONE); >+ label.setText(EMFUIMessages.PathVariableDialog_locationLabel); >+ data = new GridData(SWT.BEGINNING); >+ label.setLayoutData(data); >+ >+ locationText = new Text(composite, SWT.BORDER); >+ data = new GridData(GridData.FILL_HORIZONTAL); >+ data.grabExcessHorizontalSpace = true; >+ locationText.setLayoutData(data); >+ if (initialLocation != null) { >+ locationText.setText(initialLocation); >+ } >+ >+ Button browseButton = new Button(composite, SWT.PUSH); >+ browseButton.setText(EMFUIMessages.PathVariableDialog_browseButton); >+ setButtonLayoutData(browseButton); >+ >+ browseButton.addSelectionListener(new SelectionAdapter() { >+ >+ public void widgetSelected(SelectionEvent e) { >+ DirectoryDialog dlg = new DirectoryDialog(getShell()); >+ dlg.setText(EMFUIMessages.PathVariableDialog_browseDialogTitle); >+ dlg >+ .setMessage(EMFUIMessages.PathVariableDialog_browseDialogMessage); >+ >+ String folder = dlg.open(); >+ if (folder != null) { >+ locationText.setText(folder); >+ } >+ } >+ }); >+ >+ ModifyListener l = new ModifyListener() { >+ >+ public void modifyText(ModifyEvent e) { >+ validateInputs(); >+ } >+ }; >+ >+ nameText.addModifyListener(l); >+ locationText.addModifyListener(l); >+ >+ if (initialName != null) { >+ // edit mode >+ setTitle(EMFUIMessages.PathVariableDialog_editTitle); >+ >+ // select the location field text and set focus to it >+ locationText.setSelection(0, locationText.getText().length()); >+ locationText.setFocus(); >+ } else { >+ // new mode >+ setTitle(EMFUIMessages.PathVariableDialog_newTitle); >+ } >+ >+ setMessage(plainMsg); >+ >+ return result; >+ } >+ >+ /** >+ * Initially disables the OK button, because in either creation or edit >+ * mode, the user will have to input some data before it can hit OK. >+ */ >+ protected void createButtonsForButtonBar(Composite parent) { >+ super.createButtonsForButtonBar(parent); >+ >+ // initially, the OK button is disabled because we haven't yet any input >+ getButton(IDialogConstants.OK_ID).setEnabled(false); >+ } >+ >+ /** >+ * Validates the current values of the variable name and location entry >+ * fields. A warning or error message is shown in the title area, if >+ * appropriate, and the OK button is disabled if any input is invalid. >+ * Moreover, in edit mode, the OK button is disabled if the user hasn't >+ * changed either the variable name or the location. >+ */ >+ private void validateInputs() { >+ IStatus status = Status.OK_STATUS; >+ boolean isError = false; >+ >+ String name = nameText.getText(); >+ String location = locationText.getText(); >+ boolean hasName = name.length() > 0; >+ boolean hasLocation = location.length() > 0; >+ >+ if (hasName && !name.equals(initialName)) { >+ status = validateName(name); >+ } >+ >+ if (!status.isOK()) { >+ isError = true; >+ setMessage(status.getMessage(), IMessageProvider.ERROR); >+ } else if (hasLocation && !location.equals(initialLocation)) { >+ status = validateLocation(new Path(location)); >+ if (!status.isOK()) { >+ isError = status.getSeverity() >= IStatus.ERROR; >+ >+ setMessage(status.getMessage(), >+ isError ? IMessageProvider.ERROR >+ : IMessageProvider.WARNING); >+ } >+ } >+ >+ if (status.isOK()) { >+ setMessage(plainMsg); >+ } >+ >+ if (initialName != null) { >+ // edit mode. Check that either the name or the location is changed >+ if (name.equals(initialName) && location.equals(initialLocation)) { >+ // force OK button to be disabled >+ hasName = false; >+ } >+ } >+ >+ // dialog not complete if error or missing an input >+ getButton(IDialogConstants.OK_ID).setEnabled( >+ !isError && hasName && hasLocation); >+ } >+ >+ /** >+ * Validates the specified variable <code>name</code>. >+ * >+ * @param name >+ * the variable name to validate >+ * @return the result of validation, which may be OK or may contain a >+ * warning or error message to display in the title area >+ */ >+ private IStatus validateName(String name) { >+ IStatus result; >+ >+ if (pathMgr.isDefined(name) && !page.isRemoved(name) >+ || PathmapManager.isRegisteredPathVariable(name) >+ || page.isAdded(name)) { >+ result = new Status(IStatus.ERROR, MslUIPlugin.getPluginId(), >+ EMFUIMessages.PathVariableDialog_alreadyDefined_ERROR_); >+ } else if (!URI.validSegment(name)) { >+ result = new Status(IStatus.ERROR, MslUIPlugin.getPluginId(), >+ EMFUIMessages.PathVariableDialog_invalidSegment_ERROR_); >+ } else { >+ result = pathMgr.validateName(name); >+ } >+ >+ return result; >+ } >+ >+ /** >+ * Validates the specified variable <code>location</code>. >+ * >+ * @param location >+ * the variable location to validate >+ * @return the result of validation, which may be OK or may contain a >+ * warning or error message to display in the title area >+ */ >+ private IStatus validateLocation(IPath location) { >+ IStatus result; >+ File file = location.toFile(); >+ >+ if (file.exists() && !file.isDirectory()) { >+ result = new Status(IStatus.ERROR, MslUIPlugin.getPluginId(), >+ EMFUIMessages.PathVariableDialog_notFolder_ERROR_); >+ } else if (!file.exists()) { >+ result = new Status(IStatus.ERROR, MslUIPlugin.getPluginId(), >+ EMFUIMessages.PathVariableDialog_noSuchFolder_ERROR_); >+ } else { >+ result = pathMgr.validateValue(location); >+ } >+ >+ if (result.isOK()) { >+ if (page.isLocationDefined(location)) { >+ result = new Status(IStatus.WARNING, MslUIPlugin >+ .getPluginId(), >+ EMFUIMessages.PathVariableDialog_sameLocation_WARN_); >+ } >+ } >+ >+ return result; >+ } >+ >+ /** >+ * Stores the variable name and location for retrieval by the client when >+ * the user succeeds in closing the dialog by pressing the OK button. >+ * >+ * @see #getVariableName() >+ * @see #getVariableLocation() >+ */ >+ protected void okPressed() { >+ variableName = nameText.getText(); >+ variableLocation = new Path(locationText.getText()); >+ >+ super.okPressed(); >+ } >+ >+ /** >+ * Obtains the path variable name entered by the user. >+ * >+ * @return the path variable name >+ */ >+ String getVariableName() { >+ return variableName; >+ } >+ >+ /** >+ * Obtains the path variable location entered by the user. >+ * >+ * @return the path variable location >+ */ >+ IPath getVariableLocation() { >+ return variableLocation; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 159650
:
59099
|
59334
| 59365