Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 150009 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java (+1 lines)
Lines 56-61 Link Here
56
	
56
	
57
	public static String IncludeToBuildpathAction_ErrorTitle;
57
	public static String IncludeToBuildpathAction_ErrorTitle;
58
	public static String JavaProjectWizardFirstPage_DetectGroup_differendWorkspaceCC_message;
58
	public static String JavaProjectWizardFirstPage_DetectGroup_differendWorkspaceCC_message;
59
	public static String JavaProjectWizardFirstPage_EnableWorkingSet_button;
59
	public static String JavaProjectWizardFirstPage_JREGroup_specific_EE;
60
	public static String JavaProjectWizardFirstPage_JREGroup_specific_EE;
60
	public static String JavaProjectWizardFirstPage_WorkingSets_group;
61
	public static String JavaProjectWizardFirstPage_WorkingSets_group;
61
	public static String JavaProjectWizardFirstPage_WorkingSetSelection_message;
62
	public static String JavaProjectWizardFirstPage_WorkingSetSelection_message;
(-)ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties (-1 / +2 lines)
Lines 675-681 Link Here
675
JavaProjectWizardFirstPage_LocationGroup_title=Contents
675
JavaProjectWizardFirstPage_LocationGroup_title=Contents
676
JavaProjectWizardFirstPage_LocationGroup_external_desc=Create project from e&xisting source
676
JavaProjectWizardFirstPage_LocationGroup_external_desc=Create project from e&xisting source
677
JavaProjectWizardFirstPage_JREGroup_default_compliance=Use def&ault JRE (Currently ''{0}'')
677
JavaProjectWizardFirstPage_JREGroup_default_compliance=Use def&ault JRE (Currently ''{0}'')
678
JavaProjectWizardFirstPage_WorkingSetSelection_message=The selected Working Sets will contain the new project
678
JavaProjectWizardFirstPage_WorkingSetSelection_message=The new project will be added to the selected working sets:
679
JavaProjectWizardFirstPage_LocationGroup_workspace_desc=Create new project in &workspace
679
JavaProjectWizardFirstPage_LocationGroup_workspace_desc=Create new project in &workspace
680
JavaProjectWizardFirstPage_LocationGroup_locationLabel_desc=&Directory:
680
JavaProjectWizardFirstPage_LocationGroup_locationLabel_desc=&Directory:
681
JavaProjectWizardFirstPage_LocationGroup_browseButton_desc=B&rowse...
681
JavaProjectWizardFirstPage_LocationGroup_browseButton_desc=B&rowse...
Lines 686-691 Link Here
686
JavaProjectWizardFirstPage_LayoutGroup_configure=C&onfigure Defaults...
686
JavaProjectWizardFirstPage_LayoutGroup_configure=C&onfigure Defaults...
687
JavaProjectWizardFirstPage_DetectGroup_message=The wizard will automatically configure the JRE and the project layout based on the specified existing source.<a></a>
687
JavaProjectWizardFirstPage_DetectGroup_message=The wizard will automatically configure the JRE and the project layout based on the specified existing source.<a></a>
688
JavaProjectWizardFirstPage_DetectGroup_jre_message=The current workspace uses a {1} JRE with compiler compliance level {0}. This is not recommended and either the JRE or the compiler compliance level should be changed. <a>Configure...</a>
688
JavaProjectWizardFirstPage_DetectGroup_jre_message=The current workspace uses a {1} JRE with compiler compliance level {0}. This is not recommended and either the JRE or the compiler compliance level should be changed. <a>Configure...</a>
689
JavaProjectWizardFirstPage_EnableWorkingSet_button=Add project to the following working sets:
689
JavaProjectWizardFirstPage_DetectGroup_differendWorkspaceCC_message=The default compiler compliance level for the current workspace is {0}. The new project will use a project specific compiler compliance level of {1}.<a></a>
690
JavaProjectWizardFirstPage_DetectGroup_differendWorkspaceCC_message=The default compiler compliance level for the current workspace is {0}. The new project will use a project specific compiler compliance level of {1}.<a></a>
690
JavaProjectWizardFirstPage_Message_enterProjectName=Enter a project name.
691
JavaProjectWizardFirstPage_Message_enterProjectName=Enter a project name.
691
JavaProjectWizardFirstPage_Message_projectAlreadyExists=A project with this name already exists.
692
JavaProjectWizardFirstPage_Message_projectAlreadyExists=A project with this name already exists.
(-)ui/org/eclipse/jdt/internal/ui/wizards/JavaProjectWizard.java (-92 / +108 lines)
Lines 11-24 Link Here
11
package org.eclipse.jdt.internal.ui.wizards;
11
package org.eclipse.jdt.internal.ui.wizards;
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.HashSet;
17
import java.util.List;
14
18
15
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.IConfigurationElement;
17
import org.eclipse.core.runtime.IExecutableExtension;
22
import org.eclipse.core.runtime.IExecutableExtension;
18
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IProgressMonitor;
19
24
20
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.swt.widgets.Shell;
21
26
27
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.jface.viewers.ITreeSelection;
29
import org.eclipse.jface.viewers.TreePath;
30
31
import org.eclipse.ui.IWorkingSet;
22
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
32
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
23
33
24
import org.eclipse.jdt.core.IJavaElement;
34
import org.eclipse.jdt.core.IJavaElement;
Lines 26-32 Link Here
26
36
27
import org.eclipse.jdt.internal.ui.JavaPlugin;
37
import org.eclipse.jdt.internal.ui.JavaPlugin;
28
import org.eclipse.jdt.internal.ui.JavaPluginImages;
38
import org.eclipse.jdt.internal.ui.JavaPluginImages;
39
import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
29
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
40
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
41
import org.eclipse.jdt.internal.ui.workingsets.OthersWorkingSetUpdater;
42
import org.eclipse.jdt.internal.ui.workingsets.WorkingSetModel;
30
43
31
public class JavaProjectWizard extends NewElementWizard implements IExecutableExtension {
44
public class JavaProjectWizard extends NewElementWizard implements IExecutableExtension {
32
    
45
    
Lines 47-53 Link Here
47
    public void addPages() {
60
    public void addPages() {
48
        super.addPages();
61
        super.addPages();
49
        fFirstPage= new JavaProjectWizardFirstPage();
62
        fFirstPage= new JavaProjectWizardFirstPage();
50
//        fFirstPage.setWorkingSets(getWorkingSets(getSelection()));
63
        fFirstPage.setWorkingSets(getWorkingSets(getSelection()));
51
        addPage(fFirstPage);
64
        addPage(fFirstPage);
52
        fSecondPage= new JavaProjectWizardSecondPage(fFirstPage);
65
        fSecondPage= new JavaProjectWizardSecondPage(fFirstPage);
53
        addPage(fSecondPage);
66
        addPage(fSecondPage);
Lines 66-100 Link Here
66
	public boolean performFinish() {
79
	public boolean performFinish() {
67
		boolean res= super.performFinish();
80
		boolean res= super.performFinish();
68
		if (res) {
81
		if (res) {
69
//			IWorkingSet[] workingSets= fFirstPage.getWorkingSets();
82
			IWorkingSet[] workingSets= fFirstPage.getWorkingSets();
70
//			for (int i= 0; i < workingSets.length; i++) {
83
			for (int i= 0; i < workingSets.length; i++) {
71
//				IWorkingSet workingSet= workingSets[i];
84
				IWorkingSet workingSet= workingSets[i];
72
//				IAdaptable[] elements= workingSet.getElements();
85
				IAdaptable[] elements= workingSet.getElements();
73
//				IAdaptable[] newElements= new IAdaptable[elements.length + 1];
86
				IAdaptable[] newElements= new IAdaptable[elements.length + 1];
74
//				System.arraycopy(elements, 0, newElements, 0, elements.length);
87
				System.arraycopy(elements, 0, newElements, 0, elements.length);
75
//				IJavaElement element= getCreatedElement();
88
				IJavaElement element= getCreatedElement();
76
//				newElements[newElements.length - 1]= element;
89
				newElements[newElements.length - 1]= element;
77
//				workingSet.setElements(newElements);
90
				workingSet.setElements(newElements);
78
//			}
91
			}
79
//			
92
			
80
//			PackageExplorerPart explorerPart= PackageExplorerPart.getFromActivePerspective();
93
			PackageExplorerPart explorerPart= PackageExplorerPart.getFromActivePerspective();
81
//			if (explorerPart != null && workingSets.length > 0) {
94
			if (explorerPart != null && workingSets.length > 0) {
82
//				WorkingSetModel workingSetModel= explorerPart.getWorkingSetModel();
95
				WorkingSetModel workingSetModel= explorerPart.getWorkingSetModel();
83
//				HashSet active= new HashSet(Arrays.asList(workingSetModel.getActiveWorkingSets()));
96
				HashSet active= new HashSet(Arrays.asList(workingSetModel.getActiveWorkingSets()));
84
//				
97
				
85
//				boolean hasChange= false;
98
				boolean hasChange= false;
86
//				for (int j= 0; j < workingSets.length; j++) {
99
				for (int j= 0; j < workingSets.length; j++) {
87
//					IWorkingSet workingSet= workingSets[j];
100
					IWorkingSet workingSet= workingSets[j];
88
//					if (!active.contains(workingSet)) {
101
					if (!active.contains(workingSet)) {
89
//						active.add(workingSet);
102
						active.add(workingSet);
90
//						hasChange= true;
103
						hasChange= true;
91
//					}
104
					}
92
//				}
105
				}
93
//				
106
				
94
//				if (hasChange) {
107
				if (hasChange) {
95
//					workingSetModel.setActiveWorkingSets((IWorkingSet[])active.toArray(new IWorkingSet[active.size()]));
108
					workingSetModel.setActiveWorkingSets((IWorkingSet[])active.toArray(new IWorkingSet[active.size()]));
96
//				}
109
				}
97
//			}
110
			}
98
			
111
			
99
			BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
112
			BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
100
	 		selectAndReveal(fSecondPage.getJavaProject().getProject());
113
	 		selectAndReveal(fSecondPage.getJavaProject().getProject());
Lines 131-197 Link Here
131
		return JavaCore.create(fFirstPage.getProjectHandle());
144
		return JavaCore.create(fFirstPage.getProjectHandle());
132
	}
145
	}
133
	
146
	
134
//	private IWorkingSet[] getWorkingSets(IStructuredSelection selection) {
147
	private IWorkingSet[] getWorkingSets(IStructuredSelection selection) {
135
//		if (!(selection instanceof ITreeSelection))
148
		if (!(selection instanceof ITreeSelection))
136
//			return null;
149
			return null;
137
//		
150
		
138
//		ITreeSelection treeSelection= (ITreeSelection)selection;
151
		ITreeSelection treeSelection= (ITreeSelection)selection;
139
//		List elements= treeSelection.toList();
152
		List elements= treeSelection.toList();
140
//		if (elements.size() != 1)
153
		if (elements.size() != 1)
141
//			return null;
154
			return null;
142
//		
155
		
143
//		Object element= elements.get(0);
156
		Object element= elements.get(0);
144
//		TreePath[] paths= treeSelection.getPathsFor(element);
157
		TreePath[] paths= treeSelection.getPathsFor(element);
145
//		if (paths.length != 1)
158
		if (paths.length != 1)
146
//			return null;
159
			return null;
147
//
160
148
//		TreePath path= paths[0];
161
		TreePath path= paths[0];
149
//		if (path.getSegmentCount() == 0)
162
		if (path.getSegmentCount() == 0)
150
//			return null;
163
			return null;
151
//
164
152
//		Object candidate= path.getSegment(0);
165
		Object candidate= path.getSegment(0);
153
//		if (candidate instanceof IWorkingSet) {
166
		if (candidate instanceof IWorkingSet) {
154
//			if (isValidWorkingSet((IWorkingSet)candidate))
167
			if (isValidWorkingSet((IWorkingSet)candidate))
155
//				return new IWorkingSet[] {(IWorkingSet)candidate};
168
				return new IWorkingSet[] {(IWorkingSet)candidate};
156
//		} else {
169
		} else {
157
//			PackageExplorerPart explorerPart= PackageExplorerPart.getFromActivePerspective();
170
			PackageExplorerPart explorerPart= PackageExplorerPart.getFromActivePerspective();
158
//			if (explorerPart == null)
171
			if (explorerPart == null)
159
//				return null;
172
				return null;
160
//			
173
			
161
//			WorkingSetModel workingSetModel= explorerPart.getWorkingSetModel();
174
			WorkingSetModel workingSetModel= explorerPart.getWorkingSetModel();
162
//			IWorkingSet[] activeWorkingSets= workingSetModel.getActiveWorkingSets();
175
			if (workingSetModel == null)
163
//
176
				return null;
164
//			ArrayList result= new ArrayList();
177
			
165
//			for (int i= 0; i < activeWorkingSets.length; i++) {
178
			IWorkingSet[] activeWorkingSets= workingSetModel.getActiveWorkingSets();
166
//				IWorkingSet workingSet= activeWorkingSets[i];
179
167
//				if (contains(workingSet, candidate)) {
180
			ArrayList result= new ArrayList();
168
//					if (isValidWorkingSet(workingSet))
181
			for (int i= 0; i < activeWorkingSets.length; i++) {
169
//						result.add(workingSet);
182
				IWorkingSet workingSet= activeWorkingSets[i];
170
//				}
183
				if (contains(workingSet, candidate)) {
171
//			}
184
					if (isValidWorkingSet(workingSet))
172
//			if (result.size() == 0)
185
						result.add(workingSet);
173
//				return null;
186
				}
174
//			
187
			}
175
//			return (IWorkingSet[])result.toArray(new IWorkingSet[result.size()]);
188
			if (result.size() == 0)
176
//		}
189
				return null;
177
//		
190
			
178
//		return null;
191
			return (IWorkingSet[])result.toArray(new IWorkingSet[result.size()]);
179
//	}
192
		}
180
//
193
		
181
//	private boolean isValidWorkingSet(IWorkingSet workingSet) {
194
		return null;
182
//		if (OthersWorkingSetUpdater.ID.equals(workingSet.getId()))
195
	}
183
//			return false;
196
184
//		
197
	private boolean isValidWorkingSet(IWorkingSet workingSet) {
185
//		return true;
198
		if (OthersWorkingSetUpdater.ID.equals(workingSet.getId()))
186
//	}
199
			return false;
187
//
200
		
188
//	private boolean contains(IWorkingSet workingSet, Object candidate) {
201
		return true;
189
//		IAdaptable[] elements= workingSet.getElements();
202
	}
190
//		for (int i= 0; i < elements.length; i++) {
203
191
//			if (candidate.equals(elements[i]))
204
	private boolean contains(IWorkingSet workingSet, Object candidate) {
192
//				return true;
205
		IAdaptable[] elements= workingSet.getElements();
193
//		}
206
		for (int i= 0; i < elements.length; i++) {
194
//		return false;
207
			if (candidate.equals(elements[i]))
195
//	}
208
				return true;
209
		}
210
		return false;
211
	}
196
        
212
        
197
}
213
}
(-)ui/org/eclipse/jdt/internal/ui/wizards/JavaProjectWizardFirstPage.java (-21 / +21 lines)
Lines 614-620 Link Here
614
			workingSetGroup.setLayout(new GridLayout(1, false));
614
			workingSetGroup.setLayout(new GridLayout(1, false));
615
			
615
			
616
			String[] workingSetIds= new String[] {JavaWorkingSetUpdater.ID, "org.eclipse.ui.resourceWorkingSetPage"}; //$NON-NLS-1$
616
			String[] workingSetIds= new String[] {JavaWorkingSetUpdater.ID, "org.eclipse.ui.resourceWorkingSetPage"}; //$NON-NLS-1$
617
			fWorkingSetBlock= new WorkingSetConfigurationBlock(initialWorkingSets, workingSetIds);
617
			fWorkingSetBlock= new WorkingSetConfigurationBlock(initialWorkingSets, workingSetIds, NewWizardMessages.JavaProjectWizardFirstPage_EnableWorkingSet_button, JavaPlugin.getDefault().getDialogSettings());
618
			fWorkingSetBlock.setDialogMessage(NewWizardMessages.JavaProjectWizardFirstPage_WorkingSetSelection_message);
618
			fWorkingSetBlock.setDialogMessage(NewWizardMessages.JavaProjectWizardFirstPage_WorkingSetSelection_message);
619
			fWorkingSetBlock.createContent(workingSetGroup);
619
			fWorkingSetBlock.createContent(workingSetGroup);
620
		}
620
		}
Lines 845-852 Link Here
845
	private String fInitialName;
845
	private String fInitialName;
846
	
846
	
847
	private static final String PAGE_NAME= NewWizardMessages.JavaProjectWizardFirstPage_page_pageName;
847
	private static final String PAGE_NAME= NewWizardMessages.JavaProjectWizardFirstPage_page_pageName;
848
//	private WorkingSetGroup fWorkingSetGroup;
848
	private WorkingSetGroup fWorkingSetGroup;
849
//	private IWorkingSet[] fInitWorkingSets; 
849
	private IWorkingSet[] fInitWorkingSets; 
850
850
851
	/**
851
	/**
852
	 * Create a new <code>SimpleProjectFirstPage</code>.
852
	 * Create a new <code>SimpleProjectFirstPage</code>.
Lines 884-890 Link Here
884
		fLocationGroup= new LocationGroup(composite);
884
		fLocationGroup= new LocationGroup(composite);
885
		fJREGroup= new JREGroup(composite);
885
		fJREGroup= new JREGroup(composite);
886
		fLayoutGroup= new LayoutGroup(composite);
886
		fLayoutGroup= new LayoutGroup(composite);
887
//		fWorkingSetGroup= new WorkingSetGroup(composite, fInitWorkingSets);
887
		fWorkingSetGroup= new WorkingSetGroup(composite, fInitWorkingSets);
888
		fDetectGroup= new DetectGroup(composite);
888
		fDetectGroup= new DetectGroup(composite);
889
		
889
		
890
		// establish connections
890
		// establish connections
Lines 999-1019 Link Here
999
		return layout;
999
		return layout;
1000
	}
1000
	}
1001
1001
1002
//	/**
1002
	/**
1003
//	 * @param workingSets the initialy selected working sets or <b>null</b>
1003
	 * @param workingSets the initialy selected working sets or <b>null</b>
1004
//	 */
1004
	 */
1005
//	public void setWorkingSets(IWorkingSet[] workingSets) {
1005
	public void setWorkingSets(IWorkingSet[] workingSets) {
1006
//		if (workingSets == null) {
1006
		if (workingSets == null) {
1007
//			fInitWorkingSets= new IWorkingSet[0];
1007
			fInitWorkingSets= new IWorkingSet[0];
1008
//		} else {
1008
		} else {
1009
//			fInitWorkingSets= workingSets;
1009
			fInitWorkingSets= workingSets;
1010
//		}
1010
		}
1011
//	}
1011
	}
1012
//
1012
1013
//	/**
1013
	/**
1014
//	 * @return the selected working sets, not <b>null</b>
1014
	 * @return the selected working sets, not <b>null</b>
1015
//	 */
1015
	 */
1016
//	public IWorkingSet[] getWorkingSets() {
1016
	public IWorkingSet[] getWorkingSets() {
1017
//		return fWorkingSetGroup.getSelectedWorkingSets();
1017
		return fWorkingSetGroup.getSelectedWorkingSets();
1018
//	}
1018
	}
1019
}
1019
}
(-)ui/org/eclipse/jdt/internal/ui/workingsets/WorkingSetConfigurationBlock.java (-9 / +162 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.workingsets;
11
package org.eclipse.jdt.internal.ui.workingsets;
12
12
13
import com.ibm.icu.text.Collator;
14
15
import java.util.ArrayList;
16
import java.util.Arrays;
17
import java.util.Comparator;
18
import java.util.List;
19
13
import org.eclipse.core.runtime.Assert;
20
import org.eclipse.core.runtime.Assert;
14
21
15
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.SWT;
Lines 20-31 Link Here
20
import org.eclipse.swt.layout.GridData;
27
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridLayout;
28
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.widgets.Button;
29
import org.eclipse.swt.widgets.Button;
30
import org.eclipse.swt.widgets.Combo;
23
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Label;
32
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.swt.widgets.Text;
26
33
27
import org.eclipse.jface.dialogs.Dialog;
34
import org.eclipse.jface.dialogs.Dialog;
28
import org.eclipse.jface.dialogs.IDialogConstants;
35
import org.eclipse.jface.dialogs.IDialogConstants;
36
import org.eclipse.jface.dialogs.IDialogSettings;
29
import org.eclipse.jface.resource.JFaceResources;
37
import org.eclipse.jface.resource.JFaceResources;
30
import org.eclipse.jface.window.Window;
38
import org.eclipse.jface.window.Window;
31
39
Lines 36-60 Link Here
36
44
37
public class WorkingSetConfigurationBlock {
45
public class WorkingSetConfigurationBlock {
38
	
46
	
47
	private static final String WORKINGSET_SELECTION_HISTORY= "workingset_selection_history"; //$NON-NLS-1$
48
	private static final int MAX_HISTORY_SIZE= 5;
49
	
39
	private Label fLabel;
50
	private Label fLabel;
40
	private Text fText;
51
	private Combo fWorkingSetCombo;
41
	private Button fConfigure;
52
	private Button fConfigure;
42
	private IWorkingSet[] fSelectedWorkingSets;
53
	private IWorkingSet[] fSelectedWorkingSets;
43
	private String[] fWorkingSetIDs;
54
	private String[] fWorkingSetIDs;
44
	private String fMessage;
55
	private String fMessage;
56
	private Button fEnableButton;
57
	private ArrayList fSelectionHistory;
58
	private final IDialogSettings fSettings;
59
	private final String fEnableButtonText;
45
60
46
	/**
61
	/**
47
	 * @param preSelectedWorkingSets the working sets which are selected when showning the block, not <b>null</b>
62
	 * @param preSelectedWorkingSets the working sets which are selected when showning the block, not <b>null</b>
48
	 * @param compatibleWorkingSetIds only working sets with an id in compatibleWorkingSetIds can be selected, not <b>null</b>
63
	 * @param compatibleWorkingSetIds only working sets with an id in compatibleWorkingSetIds can be selected, not <b>null</b>
64
	 * @param enableButtonText the text shown for the enable button, not <b>null</b>
65
	 * @param settings to store/load the selection history, not <b>null</b>
49
	 */
66
	 */
50
	public WorkingSetConfigurationBlock(IWorkingSet[] preSelectedWorkingSets, String[] compatibleWorkingSetIds) {
67
	public WorkingSetConfigurationBlock(IWorkingSet[] preSelectedWorkingSets, String[] compatibleWorkingSetIds, String enableButtonText, IDialogSettings settings) {
51
		Assert.isNotNull(preSelectedWorkingSets);
68
		Assert.isNotNull(preSelectedWorkingSets);
52
		Assert.isNotNull(compatibleWorkingSetIds);
69
		Assert.isNotNull(compatibleWorkingSetIds);
70
		Assert.isNotNull(enableButtonText);
71
		Assert.isNotNull(settings);
53
		
72
		
73
		fEnableButtonText= enableButtonText;
54
		fSelectedWorkingSets= preSelectedWorkingSets;
74
		fSelectedWorkingSets= preSelectedWorkingSets;
55
		fWorkingSetIDs= compatibleWorkingSetIds;
75
		fWorkingSetIDs= compatibleWorkingSetIds;
76
		fSettings= settings;
77
		fSelectionHistory= loadSelectionHistory(settings, compatibleWorkingSetIds);
56
	}
78
	}
57
	
79
58
	/**
80
	/**
59
	 * @param message the message to show to the user in the working set selection dialog
81
	 * @param message the message to show to the user in the working set selection dialog
60
	 */
82
	 */
Lines 66-72 Link Here
66
	 * @return the selected working sets, not <b>null</b>
88
	 * @return the selected working sets, not <b>null</b>
67
	 */
89
	 */
68
	public IWorkingSet[] getSelectedWorkingSets() {
90
	public IWorkingSet[] getSelectedWorkingSets() {
69
		return fSelectedWorkingSets;
91
		if (fEnableButton.getSelection()) {
92
			return fSelectedWorkingSets;
93
		} else {
94
			return new IWorkingSet[0];
95
		}
70
	}
96
	}
71
97
72
	/**
98
	/**
Lines 79-93 Link Here
79
		Composite composite= new Composite(parent, SWT.NONE);
105
		Composite composite= new Composite(parent, SWT.NONE);
80
		composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
106
		composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
81
		composite.setLayout(new GridLayout(numColumn, false));
107
		composite.setLayout(new GridLayout(numColumn, false));
108
		
109
		fEnableButton= new Button(composite, SWT.CHECK);
110
		fEnableButton.setText(fEnableButtonText);
111
		GridData enableData= new GridData(SWT.FILL, SWT.CENTER, true, false);
112
		enableData.horizontalSpan= numColumn;
113
		fEnableButton.setLayoutData(enableData);
114
		fEnableButton.setSelection(fSelectedWorkingSets.length > 0);
82
					
115
					
83
		fLabel= new Label(composite, SWT.NONE);
116
		fLabel= new Label(composite, SWT.NONE);
84
		fLabel.setText(WorkingSetMessages.WorkingSetConfigurationBlock_WorkingSetText_name);
117
		fLabel.setText(WorkingSetMessages.WorkingSetConfigurationBlock_WorkingSetText_name);
85
		
118
		
86
		fText= new Text(composite, SWT.READ_ONLY | SWT.BORDER);
119
		fWorkingSetCombo= new Combo(composite, SWT.READ_ONLY | SWT.BORDER);
87
		GridData textData= new GridData(SWT.FILL, SWT.CENTER, true, false);
120
		GridData textData= new GridData(SWT.FILL, SWT.CENTER, true, false);
88
		textData.horizontalSpan= numColumn - 2;
121
		textData.horizontalSpan= numColumn - 2;
89
		textData.horizontalIndent= 0;
122
		textData.horizontalIndent= 0;
90
		fText.setLayoutData(textData);
123
		fWorkingSetCombo.setLayoutData(textData);
91
		
124
		
92
		fConfigure= new Button(composite, SWT.PUSH);
125
		fConfigure= new Button(composite, SWT.PUSH);
93
		fConfigure.setText(WorkingSetMessages.WorkingSetConfigurationBlock_SelectWorkingSet_button);
126
		fConfigure.setText(WorkingSetMessages.WorkingSetConfigurationBlock_SelectWorkingSet_button);
Lines 117-123 Link Here
117
			}
150
			}
118
		});
151
		});
119
		
152
		
120
		updateWorkingSetSelection();
153
		fEnableButton.addSelectionListener(new SelectionAdapter() {
154
			public void widgetSelected(SelectionEvent e) {
155
				updateEnableState(fEnableButton.getSelection());
156
			}
157
		});
158
		updateEnableState(fEnableButton.getSelection());
159
		
160
		fWorkingSetCombo.addSelectionListener(new SelectionAdapter() {
161
			public void widgetSelected(SelectionEvent e) {
162
				updateSelectedWorkingSets();
163
			}
164
		});
165
		
166
		fWorkingSetCombo.setItems(getHistoryEntries());
167
		if (fSelectedWorkingSets.length == 0 && fSelectionHistory.size() > 0) {
168
			fWorkingSetCombo.select(historyIndex((String)fSelectionHistory.get(0)));
169
			updateSelectedWorkingSets();
170
		} else {
171
			updateWorkingSetSelection();
172
		}
173
	}
174
	
175
	private void updateEnableState(boolean enabled) {
176
		fLabel.setEnabled(enabled);
177
		fWorkingSetCombo.setEnabled(enabled);
178
		fConfigure.setEnabled(enabled);
121
	}
179
	}
122
	
180
	
123
	private void updateWorkingSetSelection() {
181
	private void updateWorkingSetSelection() {
Lines 131-138 Link Here
131
				buf.append(ws.getLabel());
189
				buf.append(ws.getLabel());
132
			}
190
			}
133
		}
191
		}
192
			
193
		String currentSelection= buf.toString();
194
		int index= historyIndex(currentSelection);
195
		if (index >= 0) {
196
			historyInsert(currentSelection);
197
			fWorkingSetCombo.select(index);
198
		} else {
199
			historyInsert(currentSelection);
200
			fWorkingSetCombo.setItems(getHistoryEntries());
201
			fWorkingSetCombo.select(historyIndex(currentSelection));
202
		}
203
	}
204
205
	private String[] getHistoryEntries() {
206
		String[] history= (String[])fSelectionHistory.toArray(new String[fSelectionHistory.size()]);
207
		Arrays.sort(history, new Comparator() {
208
			public int compare(Object o1, Object o2) {
209
				return Collator.getInstance().compare(o1, o2);
210
			}
211
		});
212
		return history;
213
	}
214
215
	private void historyInsert(String entry) {
216
		fSelectionHistory.remove(entry);
217
		fSelectionHistory.add(0, entry);
218
		storeSelectionHistory(fSettings);
219
	}
220
221
	private int historyIndex(String entry) {
222
		for (int i= 0; i < fWorkingSetCombo.getItemCount(); i++) {
223
			if (fWorkingSetCombo.getItem(i).equals(entry))
224
				return i;
225
		}
226
		
227
		return -1;
228
	}
229
	
230
	private void updateSelectedWorkingSets() {
231
		String item= fWorkingSetCombo.getItem(fWorkingSetCombo.getSelectionIndex());
232
		String[] workingSetNames= item.split(", "); //$NON-NLS-1$
233
		
234
		IWorkingSetManager workingSetManager= PlatformUI.getWorkbench().getWorkingSetManager();
235
		fSelectedWorkingSets= new IWorkingSet[workingSetNames.length];
236
		for (int i= 0; i < workingSetNames.length; i++) {					
237
			IWorkingSet set= workingSetManager.getWorkingSet(workingSetNames[i]);
238
			Assert.isNotNull(set);
239
			fSelectedWorkingSets[i]= set;
240
		}
241
	}
242
	
243
	private void storeSelectionHistory(IDialogSettings settings) {
244
		String[] history;
245
		if (fSelectionHistory.size() > MAX_HISTORY_SIZE) {
246
			List subList= fSelectionHistory.subList(0, MAX_HISTORY_SIZE);
247
			history= (String[])subList.toArray(new String[subList.size()]);
248
		} else {
249
			history= (String[])fSelectionHistory.toArray(new String[fSelectionHistory.size()]);
250
		}
251
		settings.put(WORKINGSET_SELECTION_HISTORY, history);
252
	}
253
	
254
	private ArrayList loadSelectionHistory(IDialogSettings settings, String[] compatibleWorkingSetIds) {
255
		String[] strings= settings.getArray(WORKINGSET_SELECTION_HISTORY);
256
		if (strings == null || strings.length == 0)
257
			return new ArrayList();
258
		
259
		ArrayList result= new ArrayList();
260
		
261
		IWorkingSetManager workingSetManager= PlatformUI.getWorkbench().getWorkingSetManager();
262
		for (int i= 0; i < strings.length; i++) {
263
			String[] workingSetNames= strings[i].split(", "); //$NON-NLS-1$
264
			boolean valid= true;
265
			for (int j= 0; j < workingSetNames.length && valid; j++) {				
266
				IWorkingSet workingSet= workingSetManager.getWorkingSet(workingSetNames[j]);
267
				if (workingSet == null) {
268
					valid= false;
269
				} else {
270
					if (!contains(compatibleWorkingSetIds, workingSet.getId()))
271
						valid= false;
272
				}
273
			}
274
			if (valid) {
275
				result.add(strings[i]);
276
			}
277
		}
278
		
279
		return result;
280
	}
281
282
	private boolean contains(String[] compatibleWorkingSetIds, String id) {
283
		for (int i= 0; i < compatibleWorkingSetIds.length; i++) {
284
			if (compatibleWorkingSetIds[i].equals(id))
285
				return true;
286
		}
134
		
287
		
135
		fText.setText(buf.toString());
288
		return false;
136
	}
289
	}
137
	
290
	
138
	private static int getButtonWidthHint(Button button) {
291
	private static int getButtonWidthHint(Button button) {

Return to bug 150009