View | Details | Raw Unified | Return to bug 208085 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ui/internal/ide/dialogs/PathVariablesGroup.java (-2 / +118 lines)
Lines 12-17 Link Here
12
12
13
import java.util.HashSet;
13
import java.util.HashSet;
14
import java.util.Iterator;
14
import java.util.Iterator;
15
import java.util.List;
15
import java.util.Map;
16
import java.util.Map;
16
import java.util.Set;
17
import java.util.Set;
17
import java.util.SortedMap;
18
import java.util.SortedMap;
Lines 123-128 Link Here
123
    // unknown (non-existent) image. created locally, dispose locally
124
    // unknown (non-existent) image. created locally, dispose locally
124
    private Image imageUnkown;
125
    private Image imageUnkown;
125
126
127
	private List missingPaths;
128
129
	private Label missingPathLabel;
130
131
	private Table missingPathTable;
132
126
    /**
133
    /**
127
     * Creates a new PathVariablesGroup.
134
     * Creates a new PathVariablesGroup.
128
     *
135
     *
Lines 159-165 Link Here
159
    }
166
    }
160
167
161
    /**
168
    /**
162
     * Opens a dialog for creating a new variable.
169
     * Creates a new PathVariablesGroup.  This constructor differs in that
170
     * it will display a list of resources that refer to missing path variables.
171
     * 
172
     * @param multiSelect create a multi select tree
173
     * @param variableType the type of variables that are displayed in
174
     *  the widget group.  <code>IResource.FILE</code> and/or <code>IResource.FOLDER</code>
175
     *  logically ORed together.
176
     * @param missingPaths list of <code>IPath</code> elements that refer to missing
177
     *  path variables.
178
     */
179
    public PathVariablesGroup(boolean multiSelect, int variableType,
180
    		List missingPaths){
181
    	this(multiSelect, variableType);
182
    	this.missingPaths = missingPaths;
183
    }
184
    /**
185
     * Opens a dialog for creating a new variable.  If a missing path
186
     * is selected in the missing path table, the variable name will be 
187
     * initialized to the missing variable name.
163
     */
188
     */
164
    private void addNewVariable() {
189
    private void addNewVariable() {
165
        // constructs a dialog for editing the new variable's current name and value
190
        // constructs a dialog for editing the new variable's current name and value
Lines 167-172 Link Here
167
                PathVariableDialog.NEW_VARIABLE, variableType,
192
                PathVariableDialog.NEW_VARIABLE, variableType,
168
                pathVariableManager, tempPathVariables.keySet());
193
                pathVariableManager, tempPathVariables.keySet());
169
194
195
        // if the missing path table exists and has a selection, use the selected
196
        // item to initialize the variable name
197
        if (missingPathTable != null && missingPathTable.getSelectionIndex() >= 0){
198
        	IPath selectedPath = (IPath) missingPathTable.getItem(missingPathTable.getSelectionIndex()).getData();
199
        	dialog.setVariableName(selectedPath.segment(0));
200
        }
170
        // opens the dialog - just returns if the user cancels it
201
        // opens the dialog - just returns if the user cancels it
171
        if (dialog.open() == Window.CANCEL) {
202
        if (dialog.open() == Window.CANCEL) {
172
			return;
203
			return;
Lines 231-236 Link Here
231
        variableTable = new Table(pageComponent, tableStyle);
262
        variableTable = new Table(pageComponent, tableStyle);
232
        variableTable.addSelectionListener(new SelectionAdapter() {
263
        variableTable.addSelectionListener(new SelectionAdapter() {
233
            public void widgetSelected(SelectionEvent e) {
264
            public void widgetSelected(SelectionEvent e) {
265
            	updateTableSelected(e);
234
                updateEnabledState();
266
                updateEnabledState();
235
                if (selectionListener != null) {
267
                if (selectionListener != null) {
236
					selectionListener.handleEvent(new Event());
268
					selectionListener.handleEvent(new Event());
Lines 243-255 Link Here
243
        variableTable.setFont(font);
275
        variableTable.setFont(font);
244
276
245
        createButtonGroup(pageComponent);
277
        createButtonGroup(pageComponent);
246
        // populate table with current internal state and set buttons' initial state
278
        
279
        // if missing paths passed in constructor, create the
280
        // missing path table
281
        if (missingPaths != null){
282
        	createMissingPathsGroup(pageComponent);
283
        }
284
        
285
        // populate tables with current internal state and set buttons' initial state
247
        updateWidgetState(null);
286
        updateWidgetState(null);
248
287
249
        return pageComponent;
288
        return pageComponent;
250
    }
289
    }
251
290
252
    /**
291
    /**
292
	 * @param e
293
	 */
294
	protected void updateTableSelected(SelectionEvent e) {
295
		if (e.getSource() == variableTable){
296
			// clear missing path selection when variable table selected
297
			if (missingPathTable != null){
298
				missingPathTable.deselectAll();
299
			}
300
		}
301
		// clear variable table selection when missing path table selected
302
		else if (e.getSource() == missingPathTable) {
303
			variableTable.deselectAll();
304
		}
305
		
306
	}
307
308
	/**
309
	 * Create missing path table to display the list of resources
310
	 * that refer to a missing path variable
311
	 * 
312
	 * @param pageComponent parent component
313
	 */
314
	private void createMissingPathsGroup(Composite pageComponent) {
315
        GridData data = new GridData(GridData.FILL_BOTH);
316
        // layout the table
317
        missingPathLabel = new Label(pageComponent, SWT.LEFT);
318
        missingPathLabel.setText("Undefined"); //$NON-NLS-1$
319
        data = new GridData();
320
        data.horizontalAlignment = GridData.FILL;
321
        data.horizontalSpan = 2;
322
        missingPathLabel.setLayoutData(data);
323
        missingPathLabel.setFont(pageComponent.getFont());
324
325
        int tableStyle = SWT.BORDER | SWT.FULL_SELECTION;
326
        missingPathTable = new Table(pageComponent, tableStyle);
327
        missingPathTable.addSelectionListener(new SelectionAdapter() {
328
            public void widgetSelected(SelectionEvent e) {
329
            	updateTableSelected(e);
330
                updateEnabledState();
331
            }
332
        });
333
        data = new GridData(GridData.FILL_BOTH);
334
        int numberItems = missingPaths.size() > 7 ? 7 : missingPaths.size();
335
        data.heightHint = missingPathTable.getItemHeight() * numberItems;
336
        missingPathTable.setLayoutData(data);
337
        missingPathTable.setFont(pageComponent.getFont());
338
		
339
	}
340
341
	/**
253
     * Disposes the group's resources. 
342
     * Disposes the group's resources. 
254
     */
343
     */
255
    public void dispose() {
344
    public void dispose() {
Lines 578-583 Link Here
578
     */
667
     */
579
    private void updateWidgetState(String selectedVarName) {
668
    private void updateWidgetState(String selectedVarName) {
580
        updateVariableTable(selectedVarName);
669
        updateVariableTable(selectedVarName);
670
       	updateMissingPathTable();
581
        updateEnabledState();
671
        updateEnabledState();
582
    }
672
    }
673
674
	/**
675
     * Rebuilds missing path table widget state with the current list of 
676
     * paths with missing path variables. Paths that refer to variables
677
     * added to the temp variable list will not be displayed in the table.
678
	 */
679
	private void updateMissingPathTable() {
680
		if (missingPathTable != null){
681
			missingPathTable.removeAll();
682
			for (Iterator paths = missingPaths.iterator(); paths.hasNext();){
683
				IPath missingPath = (IPath) paths.next();
684
				// variable name is always the first segment
685
				String variableName = missingPath.segment(0);
686
				IPath resolvedPath = (IPath) tempPathVariables.get(variableName);
687
				if (resolvedPath == null){
688
					// path variable has still not been defined so include
689
					// the path in the table
690
					TableItem item = new TableItem(missingPathTable, SWT.NONE);
691
					item.setText(missingPath.segment(0) + " - " + missingPath ); //$NON-NLS-1$ 
692
					item.setData(missingPath);
693
					item.setImage(imageUnkown);
694
				}
695
			}
696
		}
697
		
698
	}
583
}
699
}
(-)src/org/eclipse/ui/internal/wizards/datatransfer/WizardProjectsImportPage.java (+39 lines)
Lines 32-37 Link Here
32
import org.eclipse.core.resources.IProject;
32
import org.eclipse.core.resources.IProject;
33
import org.eclipse.core.resources.IProjectDescription;
33
import org.eclipse.core.resources.IProjectDescription;
34
import org.eclipse.core.resources.IResource;
34
import org.eclipse.core.resources.IResource;
35
import org.eclipse.core.resources.IResourceStatus;
35
import org.eclipse.core.resources.IWorkspace;
36
import org.eclipse.core.resources.IWorkspace;
36
import org.eclipse.core.resources.ResourcesPlugin;
37
import org.eclipse.core.resources.ResourcesPlugin;
37
import org.eclipse.core.runtime.CoreException;
38
import org.eclipse.core.runtime.CoreException;
Lines 71-82 Link Here
71
import org.eclipse.swt.widgets.DirectoryDialog;
72
import org.eclipse.swt.widgets.DirectoryDialog;
72
import org.eclipse.swt.widgets.FileDialog;
73
import org.eclipse.swt.widgets.FileDialog;
73
import org.eclipse.swt.widgets.Label;
74
import org.eclipse.swt.widgets.Label;
75
import org.eclipse.swt.widgets.Shell;
74
import org.eclipse.swt.widgets.Text;
76
import org.eclipse.swt.widgets.Text;
75
import org.eclipse.ui.actions.WorkspaceModifyOperation;
77
import org.eclipse.ui.actions.WorkspaceModifyOperation;
76
import org.eclipse.ui.dialogs.IOverwriteQuery;
78
import org.eclipse.ui.dialogs.IOverwriteQuery;
77
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
79
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
78
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
80
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
79
import org.eclipse.ui.internal.ide.StatusUtil;
81
import org.eclipse.ui.internal.ide.StatusUtil;
82
import org.eclipse.ui.internal.ide.dialogs.MissingPathVariableDialog;
80
import org.eclipse.ui.statushandlers.StatusManager;
83
import org.eclipse.ui.statushandlers.StatusManager;
81
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
84
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
82
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
85
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
Lines 255-260 Link Here
255
	// The last selected path to mimize searches
258
	// The last selected path to mimize searches
256
	private String lastPath;
259
	private String lastPath;
257
260
261
	private Shell shell;
262
258
	/**
263
	/**
259
	 * Creates a new project creation wizard page.
264
	 * Creates a new project creation wizard page.
260
	 * 
265
	 * 
Lines 282-287 Link Here
282
	 */
287
	 */
283
	public void createControl(Composite parent) {
288
	public void createControl(Composite parent) {
284
289
290
		shell = parent.getShell();
285
		initializeDialogUnits(parent);
291
		initializeDialogUnits(parent);
286
292
287
		Composite workArea = new Composite(parent, SWT.NONE);
293
		Composite workArea = new Composite(parent, SWT.NONE);
Lines 1186-1191 Link Here
1186
					30));
1192
					30));
1187
			project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(
1193
			project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(
1188
					monitor, 70));
1194
					monitor, 70));
1195
			validateResourceLinks(workspace, project);
1189
		} catch (CoreException e) {
1196
		} catch (CoreException e) {
1190
			throw new InvocationTargetException(e);
1197
			throw new InvocationTargetException(e);
1191
		} finally {
1198
		} finally {
Lines 1211-1216 Link Here
1211
	}
1218
	}
1212
1219
1213
	/**
1220
	/**
1221
	 * Check all linked resources to see if the referenced path variable
1222
	 * is defined in the workspace.
1223
	 * 
1224
	 * @param workspace the workspace
1225
	 * @param project the project being imported
1226
	 * @throws CoreException
1227
	 */
1228
	private void validateResourceLinks(final IWorkspace workspace,
1229
			final IProject project) throws CoreException {
1230
		final ArrayList missingLinks = new ArrayList();
1231
		IResource[] projectResources = project.members();
1232
		for (int i = 0; i < projectResources.length; i++) {
1233
			IResource resource = projectResources[i];
1234
			if (resource.isLinked()){
1235
				final IStatus status = workspace.validateLinkLocation(resource, resource.getRawLocation());
1236
				if (IResourceStatus.VARIABLE_NOT_DEFINED_WARNING == status.getCode()){
1237
					missingLinks.add(resource.getRawLocation());
1238
				}
1239
			}
1240
		}
1241
		if (!missingLinks.isEmpty()){
1242
			final MissingPathVariableDialog missingDialog = new MissingPathVariableDialog(shell, missingLinks);
1243
			getShell().getDisplay().asyncExec(new Runnable(){
1244
				public void run() {
1245
					missingDialog.open();
1246
				}
1247
			});
1248
			
1249
		}
1250
	}
1251
1252
	/**
1214
	 * The <code>WizardDataTransfer</code> implementation of this
1253
	 * The <code>WizardDataTransfer</code> implementation of this
1215
	 * <code>IOverwriteQuery</code> method asks the user whether the existing
1254
	 * <code>IOverwriteQuery</code> method asks the user whether the existing
1216
	 * resource at the given path should be overwritten.
1255
	 * resource at the given path should be overwritten.
(-)src/org/eclipse/ui/internal/ide/dialogs/MissingPathVariableDialog.java (+132 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     David Wegener
11
 ******************************************************************************/
12
13
package org.eclipse.ui.internal.ide.dialogs;
14
15
import java.util.List;
16
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.jface.dialogs.Dialog;
19
import org.eclipse.jface.dialogs.IDialogConstants;
20
import org.eclipse.jface.dialogs.TitleAreaDialog;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Control;
28
import org.eclipse.swt.widgets.Shell;
29
30
/**
31
 * Dialog that displays currently defined path variables and a list
32
 * of resources that refer to a path variable that hasn't been defined
33
 * in the workspace.  The use can use the dialog to define the missing
34
 * path variables.
35
 * 
36
 * @since 3.4
37
 *
38
 */
39
public class MissingPathVariableDialog extends TitleAreaDialog {
40
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.jface.window.Window#close()
43
	 */
44
	public boolean close() {
45
		if (imageUnkown != null){
46
			imageUnkown.dispose();
47
			imageUnkown = null;
48
		}
49
		return super.close();
50
	}
51
52
	private List missingPaths;
53
	private Button okButton;
54
	private Image imageUnkown;
55
	private PathVariablesGroup pathVariablesGroup;
56
	/**
57
	 * Constructs a dialog to show missing path variables and allow the user
58
	 * to define them.
59
	 * 
60
	 * @param parentShell the parent shell
61
	 * @param missingNames list of <code>IPath</code> resources that refer to
62
	 *  a missing path variable
63
	 */
64
	public MissingPathVariableDialog(Shell parentShell, List missingNames) {
65
		super(parentShell);
66
		this.missingPaths = missingNames;
67
		pathVariablesGroup = new PathVariablesGroup(false, IResource.FILE | IResource.FOLDER, missingPaths);
68
	}
69
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
72
	 */
73
	protected Control createDialogArea(Composite parent) {
74
	    // top level composite
75
	    Composite parentComposite = (Composite) super.createDialogArea(parent);
76
	
77
	    initializeDialogUnits(parentComposite);
78
	    
79
	    // creates dialog area composite
80
	    Composite contents = createComposite(parentComposite);
81
	    pathVariablesGroup.createContents(contents);
82
	
83
	    Dialog.applyDialogFont(parentComposite);
84
	    
85
	    return contents;
86
	}
87
88
	/**
89
	 * Creates and configures this dialog's main composite.
90
	 * 
91
	 * @param parentComposite parent's composite
92
	 * @return this dialog's main composite
93
	 */
94
	private Composite createComposite(Composite parentComposite) {
95
	    // creates a composite with standard margins and spacing
96
	    Composite contents = new Composite(parentComposite, SWT.NONE);
97
	
98
	    GridLayout layout = new GridLayout();
99
	
100
	    contents.setLayout(layout);
101
	    contents.setLayoutData(new GridData(GridData.FILL_BOTH));
102
	
103
		setTitle("Undefined Path Variables"); //$NON-NLS-1$
104
	    setMessage("Project references undefined PATH variables"); //$NON-NLS-1$
105
	    return contents;
106
	}
107
108
	/**
109
	 * Adds buttons to this dialog's button bar.
110
	 * 
111
	 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar
112
	 */
113
	protected void createButtonsForButtonBar(Composite parent) {
114
	    okButton = createButton(parent, IDialogConstants.OK_ID,
115
	            IDialogConstants.OK_LABEL, true);
116
	    okButton.setEnabled(true);
117
	
118
	    createButton(parent, IDialogConstants.CANCEL_ID,
119
	            IDialogConstants.CANCEL_LABEL, false);
120
	}
121
122
	/* (non-Javadoc)
123
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
124
	 */
125
	protected void okPressed() {
126
		if (pathVariablesGroup != null){
127
			pathVariablesGroup.performOk();
128
		}
129
		super.okPressed();
130
	}
131
132
}

Return to bug 208085