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 (+2 lines)
Lines 57-62 Link Here
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_JREGroup_specific_EE;
59
	public static String JavaProjectWizardFirstPage_JREGroup_specific_EE;
60
	public static String JavaProjectWizardFirstPage_WorkingSets_group;
61
	public static String JavaProjectWizardFirstPage_WorkingSetSelection_message;
60
	
62
	
61
	public static String NewElementWizard_op_error_title;
63
	public static String NewElementWizard_op_error_title;
62
	public static String NewElementWizard_op_error_message;
64
	public static String NewElementWizard_op_error_message;
(-)ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties (+2 lines)
Lines 675-680 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_LocationGroup_workspace_desc=Create new project in &workspace
679
JavaProjectWizardFirstPage_LocationGroup_workspace_desc=Create new project in &workspace
679
JavaProjectWizardFirstPage_LocationGroup_locationLabel_desc=&Directory:
680
JavaProjectWizardFirstPage_LocationGroup_locationLabel_desc=&Directory:
680
JavaProjectWizardFirstPage_LocationGroup_browseButton_desc=B&rowse...
681
JavaProjectWizardFirstPage_LocationGroup_browseButton_desc=B&rowse...
Lines 962-967 Link Here
962
JavaProjectWizardSecondPage_problem_restore_project=Problem while restoring backup for .project
963
JavaProjectWizardSecondPage_problem_restore_project=Problem while restoring backup for .project
963
JavaProjectWizardSecondPage_problem_restore_classpath=Problem while restoring backup for .classpath
964
JavaProjectWizardSecondPage_problem_restore_classpath=Problem while restoring backup for .classpath
964
JavaProjectWizardFirstPage_directory_message=Choose a directory for the project contents:
965
JavaProjectWizardFirstPage_directory_message=Choose a directory for the project contents:
966
JavaProjectWizardFirstPage_WorkingSets_group=Working Sets
965
967
966
968
967
UserLibraryWizardPage_title=User Library
969
UserLibraryWizardPage_title=User Library
(-)ui/org/eclipse/jdt/internal/ui/wizards/JavaProjectWizard.java (-27 / +84 lines)
Lines 11-17 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.Iterator;
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.HashSet;
15
import java.util.List;
17
import java.util.List;
16
18
17
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
Lines 34-41 Link Here
34
36
35
import org.eclipse.jdt.internal.ui.JavaPlugin;
37
import org.eclipse.jdt.internal.ui.JavaPlugin;
36
import org.eclipse.jdt.internal.ui.JavaPluginImages;
38
import org.eclipse.jdt.internal.ui.JavaPluginImages;
39
import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
37
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
40
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
38
import org.eclipse.jdt.internal.ui.workingsets.JavaWorkingSetUpdater;
41
import org.eclipse.jdt.internal.ui.workingsets.OthersWorkingSetUpdater;
42
import org.eclipse.jdt.internal.ui.workingsets.WorkingSetModel;
39
43
40
public class JavaProjectWizard extends NewElementWizard implements IExecutableExtension {
44
public class JavaProjectWizard extends NewElementWizard implements IExecutableExtension {
41
    
45
    
Lines 56-61 Link Here
56
    public void addPages() {
60
    public void addPages() {
57
        super.addPages();
61
        super.addPages();
58
        fFirstPage= new JavaProjectWizardFirstPage();
62
        fFirstPage= new JavaProjectWizardFirstPage();
63
        fFirstPage.setWorkingSets(getWorkingSets(getSelection()));
59
        addPage(fFirstPage);
64
        addPage(fFirstPage);
60
        fSecondPage= new JavaProjectWizardSecondPage(fFirstPage);
65
        fSecondPage= new JavaProjectWizardSecondPage(fFirstPage);
61
        addPage(fSecondPage);
66
        addPage(fSecondPage);
Lines 74-81 Link Here
74
	public boolean performFinish() {
79
	public boolean performFinish() {
75
		boolean res= super.performFinish();
80
		boolean res= super.performFinish();
76
		if (res) {
81
		if (res) {
77
			IWorkingSet workingSet= getWorkingSet(getSelection());
82
			IWorkingSet[] workingSets= fFirstPage.getWorkingSets();
78
			if (workingSet != null && JavaWorkingSetUpdater.ID.equals(workingSet.getId())) {
83
			for (int i= 0; i < workingSets.length; i++) {
84
				IWorkingSet workingSet= workingSets[i];
79
				IAdaptable[] elements= workingSet.getElements();
85
				IAdaptable[] elements= workingSet.getElements();
80
				IAdaptable[] newElements= new IAdaptable[elements.length + 1];
86
				IAdaptable[] newElements= new IAdaptable[elements.length + 1];
81
				System.arraycopy(elements, 0, newElements, 0, elements.length);
87
				System.arraycopy(elements, 0, newElements, 0, elements.length);
Lines 83-95 Link Here
83
				newElements[newElements.length - 1]= element;
89
				newElements[newElements.length - 1]= element;
84
				workingSet.setElements(newElements);
90
				workingSet.setElements(newElements);
85
			}
91
			}
92
			
93
			PackageExplorerPart explorerPart= PackageExplorerPart.getFromActivePerspective();
94
			if (explorerPart != null && workingSets.length > 0) {
95
				WorkingSetModel workingSetModel= explorerPart.getWorkingSetModel();
96
				HashSet active= new HashSet(Arrays.asList(workingSetModel.getActiveWorkingSets()));
97
				
98
				boolean hasChange= false;
99
				for (int j= 0; j < workingSets.length; j++) {
100
					IWorkingSet workingSet= workingSets[j];
101
					if (!active.contains(workingSet)) {
102
						active.add(workingSet);
103
						hasChange= true;
104
					}
105
				}
106
				
107
				if (hasChange) {
108
					workingSetModel.setActiveWorkingSets((IWorkingSet[])active.toArray(new IWorkingSet[active.size()]));
109
				}
110
			}
111
			
86
			BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
112
			BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
87
	 		selectAndReveal(fSecondPage.getJavaProject().getProject());
113
	 		selectAndReveal(fSecondPage.getJavaProject().getProject());
88
		}
114
		}
89
		return res;
115
		return res;
90
	}
116
	}
91
    
117
92
    protected void handleFinishException(Shell shell, InvocationTargetException e) {
118
	protected void handleFinishException(Shell shell, InvocationTargetException e) {
93
        String title= NewWizardMessages.JavaProjectWizard_op_error_title; 
119
        String title= NewWizardMessages.JavaProjectWizard_op_error_title; 
94
        String message= NewWizardMessages.JavaProjectWizard_op_error_create_message;			 
120
        String message= NewWizardMessages.JavaProjectWizard_op_error_create_message;			 
95
        ExceptionHandler.handle(e, getShell(), title, message);
121
        ExceptionHandler.handle(e, getShell(), title, message);
Lines 118-150 Link Here
118
		return JavaCore.create(fFirstPage.getProjectHandle());
144
		return JavaCore.create(fFirstPage.getProjectHandle());
119
	}
145
	}
120
	
146
	
121
	private IWorkingSet getWorkingSet(IStructuredSelection selection) {
147
	private IWorkingSet[] getWorkingSets(IStructuredSelection selection) {
122
		if (!(selection instanceof ITreeSelection))
148
		if (!(selection instanceof ITreeSelection))
123
			return null;
149
			return null;
150
		
124
		ITreeSelection treeSelection= (ITreeSelection)selection;
151
		ITreeSelection treeSelection= (ITreeSelection)selection;
125
		List elements= treeSelection.toList();
152
		List elements= treeSelection.toList();
126
		IWorkingSet result= null;
153
		if (elements.size() != 1)
127
		for (Iterator iter= elements.iterator(); iter.hasNext();) {
154
			return null;
128
			Object element= iter.next();
155
		
129
			if (element instanceof IWorkingSet)
156
		Object element= elements.get(0);
130
				return (IWorkingSet)element;
157
		TreePath[] paths= treeSelection.getPathsFor(element);
131
			TreePath[] paths= treeSelection.getPathsFor(element);
158
		if (paths.length != 1)
132
			if (paths.length != 1)
159
			return null;
133
				return null;
160
134
			TreePath path= paths[0];
161
		TreePath path= paths[0];
135
			if (path.getSegmentCount() != 2)
162
		if (path.getSegmentCount() == 0)
136
				return null;
163
			return null;
137
			Object candidate= path.getSegment(0);
164
138
			if (!(candidate instanceof IWorkingSet))
165
		Object candidate= path.getSegment(0);
139
				return null;
166
		if (candidate instanceof IWorkingSet) {
140
			if (result == null) {
167
			if (isValidWorkingSet((IWorkingSet)candidate))
141
				result= (IWorkingSet)candidate;
168
				return new IWorkingSet[] {(IWorkingSet)candidate};
142
			} else {
169
		} else {
143
				if (result != candidate)
170
			PackageExplorerPart explorerPart= PackageExplorerPart.getFromActivePerspective();
144
					return null;
171
			WorkingSetModel workingSetModel= explorerPart.getWorkingSetModel();
172
			IWorkingSet[] activeWorkingSets= workingSetModel.getActiveWorkingSets();
173
174
			ArrayList result= new ArrayList();
175
			for (int i= 0; i < activeWorkingSets.length; i++) {
176
				IWorkingSet workingSet= activeWorkingSets[i];
177
				if (contains(workingSet, candidate)) {
178
					if (isValidWorkingSet(workingSet))
179
						result.add(workingSet);
180
				}
145
			}
181
			}
182
			if (result.size() == 0)
183
				return null;
184
			
185
			return (IWorkingSet[])result.toArray(new IWorkingSet[result.size()]);
186
		}
187
		
188
		return null;
189
	}
190
191
	private boolean isValidWorkingSet(IWorkingSet workingSet) {
192
		if (OthersWorkingSetUpdater.ID.equals(workingSet.getId()))
193
			return false;
194
		
195
		return true;
196
	}
197
198
	private boolean contains(IWorkingSet workingSet, Object candidate) {
199
		IAdaptable[] elements= workingSet.getElements();
200
		for (int i= 0; i < elements.length; i++) {
201
			if (candidate.equals(elements[i]))
202
				return true;
146
		}
203
		}
147
		return result;
204
		return false;
148
	}
205
	}
149
        
206
        
150
}
207
}
(-)ui/org/eclipse/jdt/internal/ui/wizards/JavaProjectWizardFirstPage.java (-3 / +48 lines)
Lines 47-52 Link Here
47
import org.eclipse.jface.util.Policy;
47
import org.eclipse.jface.util.Policy;
48
import org.eclipse.jface.wizard.WizardPage;
48
import org.eclipse.jface.wizard.WizardPage;
49
49
50
import org.eclipse.ui.IWorkingSet;
50
import org.eclipse.ui.PlatformUI;
51
import org.eclipse.ui.PlatformUI;
51
import org.eclipse.ui.dialogs.PreferencesUtil;
52
import org.eclipse.ui.dialogs.PreferencesUtil;
52
53
Lines 79-90 Link Here
79
import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
80
import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
80
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
81
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
81
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
82
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
83
import org.eclipse.jdt.internal.ui.workingsets.JavaWorkingSetUpdater;
84
import org.eclipse.jdt.internal.ui.workingsets.WorkingSetConfigurationBlock;
82
85
83
/**
86
/**
84
 * The first page of the <code>SimpleProjectWizard</code>.
87
 * The first page of the <code>SimpleProjectWizard</code>.
85
 */
88
 */
86
public class JavaProjectWizardFirstPage extends WizardPage {
89
public class JavaProjectWizardFirstPage extends WizardPage {
87
	
90
88
	/**
91
	/**
89
	 * Request a project name. Fires an event whenever the text field is
92
	 * Request a project name. Fires an event whenever the text field is
90
	 * changed, regardless of its content.
93
	 * changed, regardless of its content.
Lines 598-605 Link Here
598
601
599
602
600
	}
603
	}
601
602
	
604
	
605
	private final class WorkingSetGroup {
606
		
607
		private WorkingSetConfigurationBlock fWorkingSetBlock;
608
609
		public WorkingSetGroup(Composite composite, IWorkingSet[] initialWorkingSets) {
610
			Group workingSetGroup= new Group(composite, SWT.NONE);
611
			workingSetGroup.setFont(composite.getFont());
612
			workingSetGroup.setText(NewWizardMessages.JavaProjectWizardFirstPage_WorkingSets_group);
613
			workingSetGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
614
			workingSetGroup.setLayout(new GridLayout(1, false));
615
			
616
			String[] workingSetIds= new String[] {JavaWorkingSetUpdater.ID, "org.eclipse.ui.resourceWorkingSetPage"}; //$NON-NLS-1$
617
			fWorkingSetBlock= new WorkingSetConfigurationBlock(initialWorkingSets, workingSetIds);
618
			fWorkingSetBlock.setDialogMessage(NewWizardMessages.JavaProjectWizardFirstPage_WorkingSetSelection_message);
619
			fWorkingSetBlock.createContent(workingSetGroup);
620
		}
621
622
		public IWorkingSet[] getSelectedWorkingSets() {
623
			return fWorkingSetBlock.getSelectedWorkingSets();
624
		}
625
	}
626
603
	/**
627
	/**
604
	 * Show a warning when the project location contains files.
628
	 * Show a warning when the project location contains files.
605
	 */
629
	 */
Lines 820-826 Link Here
820
844
821
	private String fInitialName;
845
	private String fInitialName;
822
	
846
	
823
	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;
849
	private IWorkingSet[] fInitWorkingSets; 
824
850
825
	/**
851
	/**
826
	 * Create a new <code>SimpleProjectFirstPage</code>.
852
	 * Create a new <code>SimpleProjectFirstPage</code>.
Lines 858-863 Link Here
858
		fLocationGroup= new LocationGroup(composite);
884
		fLocationGroup= new LocationGroup(composite);
859
		fJREGroup= new JREGroup(composite);
885
		fJREGroup= new JREGroup(composite);
860
		fLayoutGroup= new LayoutGroup(composite);
886
		fLayoutGroup= new LayoutGroup(composite);
887
		fWorkingSetGroup= new WorkingSetGroup(composite, fInitWorkingSets);
861
		fDetectGroup= new DetectGroup(composite);
888
		fDetectGroup= new DetectGroup(composite);
862
		
889
		
863
		// establish connections
890
		// establish connections
Lines 971-974 Link Here
971
		}
998
		}
972
		return layout;
999
		return layout;
973
	}
1000
	}
1001
1002
	/**
1003
	 * @param workingSets the initialy selected working sets or <b>null</b>
1004
	 */
1005
	public void setWorkingSets(IWorkingSet[] workingSets) {
1006
		if (workingSets == null) {
1007
			fInitWorkingSets= new IWorkingSet[0];
1008
		} else {
1009
			fInitWorkingSets= workingSets;
1010
		}
1011
	}
1012
1013
	/**
1014
	 * @return the selected working sets, not <b>null</b>
1015
	 */
1016
	public IWorkingSet[] getWorkingSets() {
1017
		return fWorkingSetGroup.getSelectedWorkingSets();
1018
	}
974
}
1019
}
(-)ui/org/eclipse/jdt/internal/ui/actions/NewWizardsActionGroup.java (-1 / +6 lines)
Lines 27-32 Link Here
27
import org.eclipse.jdt.ui.IContextMenuConstants;
27
import org.eclipse.jdt.ui.IContextMenuConstants;
28
28
29
import org.eclipse.jdt.internal.ui.workingsets.JavaWorkingSetUpdater;
29
import org.eclipse.jdt.internal.ui.workingsets.JavaWorkingSetUpdater;
30
import org.eclipse.jdt.internal.ui.workingsets.OthersWorkingSetUpdater;
30
31
31
32
32
/**
33
/**
Lines 86-92 Link Here
86
				type == IJavaElement.TYPE;
87
				type == IJavaElement.TYPE;
87
		}
88
		}
88
		if (element instanceof IWorkingSet) {
89
		if (element instanceof IWorkingSet) {
89
			return JavaWorkingSetUpdater.ID.equals(((IWorkingSet)element).getId());
90
			String workingSetId= ((IWorkingSet)element).getId();
91
			return 
92
				JavaWorkingSetUpdater.ID.equals(workingSetId) || 
93
				"org.eclipse.ui.resourceWorkingSetPage".equals(workingSetId) || //$NON-NLS-1$
94
				OthersWorkingSetUpdater.ID.equals(workingSetId);
90
		}
95
		}
91
		return false;
96
		return false;
92
	}	
97
	}	
(-)ui/org/eclipse/jdt/internal/ui/workingsets/WorkingSetMessages.java (+5 lines)
Lines 53-61 Link Here
53
	public static String ClearWorkingSetAction_toolTip;
53
	public static String ClearWorkingSetAction_toolTip;
54
	
54
	
55
	public static String ConfigureWorkingSetAction_label;
55
	public static String ConfigureWorkingSetAction_label;
56
	public static String SimpleWorkingSetSelectionDialog_DeselectAll_button;
57
	public static String SimpleWorkingSetSelectionDialog_SelectAll_button;
58
	public static String SimpleWorkingSetSelectionDialog_SimpleSelectWorkingSetDialog_title;
56
	public static String ViewActionGroup_show_label;
59
	public static String ViewActionGroup_show_label;
57
	public static String ViewActionGroup_projects_label;
60
	public static String ViewActionGroup_projects_label;
58
	public static String ViewActionGroup_workingSets_label;
61
	public static String ViewActionGroup_workingSets_label;
62
	public static String WorkingSetConfigurationBlock_SelectWorkingSet_button;
63
	public static String WorkingSetConfigurationBlock_WorkingSetText_name;
59
	
64
	
60
	public static String WorkingSetModel_histroy_name;
65
	public static String WorkingSetModel_histroy_name;
61
	public static String WorkingSetModel_others_name;
66
	public static String WorkingSetModel_others_name;
(-)ui/org/eclipse/jdt/internal/ui/workingsets/WorkingSetMessages.properties (+5 lines)
Lines 62-67 Link Here
62
WorkingSetConfigurationDialog_down_label=&Down
62
WorkingSetConfigurationDialog_down_label=&Down
63
WorkingSetConfigurationDialog_selectAll_label=Select &All
63
WorkingSetConfigurationDialog_selectAll_label=Select &All
64
WorkingSetConfigurationDialog_deselectAll_label=Dese&lect All
64
WorkingSetConfigurationDialog_deselectAll_label=Dese&lect All
65
WorkingSetConfigurationBlock_WorkingSetText_name=Working Sets:
66
WorkingSetConfigurationBlock_SelectWorkingSet_button=S&elect...
65
67
66
#---- open close project action -------------------------------------------------------
68
#---- open close project action -------------------------------------------------------
67
OpenCloseWorkingSetAction_close_label=Clo&se Projects
69
OpenCloseWorkingSetAction_close_label=Clo&se Projects
Lines 77-79 Link Here
77
79
78
#---- Remove action -----------------------------------------------------------
80
#---- Remove action -----------------------------------------------------------
79
RemoveWorkingSetElementAction_label=Remo&ve from Working Set
81
RemoveWorkingSetElementAction_label=Remo&ve from Working Set
82
SimpleWorkingSetSelectionDialog_SimpleSelectWorkingSetDialog_title=Select Working Sets
83
SimpleWorkingSetSelectionDialog_SelectAll_button=Select &All
84
SimpleWorkingSetSelectionDialog_DeselectAll_button=&Deselect All
(-)ui/org/eclipse/jdt/internal/ui/workingsets/SimpleWorkingSetSelectionDialog.java (+229 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 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
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.workingsets;
12
13
import java.util.Arrays;
14
import java.util.Hashtable;
15
import java.util.Iterator;
16
import java.util.List;
17
import java.util.Map;
18
19
import org.eclipse.core.runtime.Assert;
20
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.SelectionAdapter;
23
import org.eclipse.swt.events.SelectionEvent;
24
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.widgets.Button;
28
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.Control;
30
import org.eclipse.swt.widgets.Shell;
31
32
import org.eclipse.jface.resource.ImageDescriptor;
33
import org.eclipse.jface.viewers.CheckStateChangedEvent;
34
import org.eclipse.jface.viewers.CheckboxTableViewer;
35
import org.eclipse.jface.viewers.ICheckStateListener;
36
import org.eclipse.jface.viewers.IStructuredContentProvider;
37
import org.eclipse.jface.viewers.LabelProvider;
38
import org.eclipse.jface.viewers.Viewer;
39
import org.eclipse.jface.viewers.ViewerFilter;
40
41
import org.eclipse.ui.IWorkingSet;
42
import org.eclipse.ui.dialogs.SelectionDialog;
43
44
public class SimpleWorkingSetSelectionDialog extends SelectionDialog {
45
	
46
	private static class WorkingSetLabelProvider extends LabelProvider {
47
		
48
		private Map fIcons;
49
		
50
		public WorkingSetLabelProvider() {
51
			fIcons= new Hashtable();
52
		}
53
		
54
		public void dispose() {
55
			Iterator iterator= fIcons.values().iterator();
56
			while (iterator.hasNext()) {
57
				Image icon= (Image)iterator.next();
58
				icon.dispose();
59
			}
60
			super.dispose();
61
		}
62
		
63
		public Image getImage(Object object) {
64
			Assert.isTrue(object instanceof IWorkingSet);
65
			IWorkingSet workingSet= (IWorkingSet)object;
66
			ImageDescriptor imageDescriptor= workingSet.getImageDescriptor();
67
			if (imageDescriptor == null)
68
				return null;
69
			
70
			Image icon= (Image)fIcons.get(imageDescriptor);
71
			if (icon == null) {
72
				icon= imageDescriptor.createImage();
73
				fIcons.put(imageDescriptor, icon);
74
			}
75
			
76
			return icon;
77
		}
78
		
79
		public String getText(Object object) {
80
			Assert.isTrue(object instanceof IWorkingSet);
81
			IWorkingSet workingSet= (IWorkingSet)object;
82
			return workingSet.getName();
83
		}
84
		
85
	}
86
	
87
	private class Filter extends ViewerFilter {
88
		
89
		public boolean select(Viewer viewer, Object parentElement, Object element) {
90
			IWorkingSet ws= (IWorkingSet)element;
91
			return accept(ws, fWorkingSetIDs) && isCompatible(ws);
92
		}
93
		
94
		private boolean accept(IWorkingSet set, String[] workingSetIDs) {
95
			for (int i= 0; i < workingSetIDs.length; i++) {
96
				if (workingSetIDs[i].equals(set.getId()))
97
					return true;
98
			}
99
			
100
			return false;
101
		}
102
		
103
		private boolean isCompatible(IWorkingSet set) {
104
			if (!set.isSelfUpdating() || set.isAggregateWorkingSet())
105
				return false;
106
			
107
			if (!set.isVisible())
108
				return false;
109
			
110
			return true;
111
		}
112
		
113
	}
114
	
115
	private final IWorkingSet[] fWorkingSet;
116
	private IWorkingSet[] fSelectedWorkingSets;
117
	private CheckboxTableViewer fTableViewer;
118
	private final String[] fWorkingSetIDs;
119
	private Button fSelectAll;
120
	private Button fDeselectAll;
121
122
	public SimpleWorkingSetSelectionDialog(Shell shell, IWorkingSet[] workingSet, String[] workingSetIDs) {
123
		super(shell);
124
		setTitle(WorkingSetMessages.SimpleWorkingSetSelectionDialog_SimpleSelectWorkingSetDialog_title);
125
		fWorkingSet= workingSet;
126
		fWorkingSetIDs= workingSetIDs;
127
	}
128
	
129
	protected Control createDialogArea(Composite parent) {
130
		Composite composite= (Composite)super.createDialogArea(parent);
131
		composite.setFont(parent.getFont());
132
133
		createMessageArea(composite);
134
		Composite inner= new Composite(composite, SWT.NONE);
135
		inner.setFont(composite.getFont());
136
		inner.setLayoutData(new GridData(GridData.FILL_BOTH));
137
		GridLayout layout= new GridLayout();
138
		layout.numColumns= 2;
139
		layout.marginHeight= 0;
140
		layout.marginWidth= 0;
141
		inner.setLayout(layout);
142
		createTableViewer(inner);
143
		createSelectionButtons(inner);
144
		
145
		return composite;
146
	}
147
148
	public void setSelection(IWorkingSet[] selectedWorkingSets) {
149
		fSelectedWorkingSets= selectedWorkingSets;
150
	}
151
152
	public IWorkingSet[] getSelection() {
153
		return fSelectedWorkingSets;
154
	}
155
	
156
	private void createTableViewer(Composite parent) {
157
		fTableViewer= CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.MULTI);
158
		fTableViewer.addCheckStateListener(new ICheckStateListener() {
159
			public void checkStateChanged(CheckStateChangedEvent event) {
160
				checkedStateChanged();
161
			}
162
		});
163
		GridData data= new GridData(GridData.FILL_BOTH);
164
		data.heightHint= convertHeightInCharsToPixels(20);
165
		data.widthHint= convertWidthInCharsToPixels(50);
166
		fTableViewer.getTable().setLayoutData(data);
167
		fTableViewer.getTable().setFont(parent.getFont());
168
169
		fTableViewer.addFilter(new Filter());
170
		fTableViewer.setLabelProvider(new WorkingSetLabelProvider());
171
		fTableViewer.setContentProvider(new IStructuredContentProvider() {
172
			public Object[] getElements(Object element) {
173
				return (Object[])element;
174
			}
175
			public void dispose() {
176
			}
177
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
178
			}
179
		});
180
		
181
		fTableViewer.setInput(fWorkingSet);
182
		fTableViewer.setCheckedElements(fSelectedWorkingSets);
183
	}
184
	
185
	private void createSelectionButtons(Composite parent) {
186
		Composite buttons= new Composite(parent, SWT.NONE);
187
		buttons.setFont(parent.getFont());
188
		buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL));
189
		GridLayout layout= new GridLayout();
190
		layout.marginHeight= 0;
191
		layout.marginWidth= 0;
192
		buttons.setLayout(layout);
193
194
		fSelectAll= new Button(buttons, SWT.PUSH);
195
		fSelectAll.setText(WorkingSetMessages.SimpleWorkingSetSelectionDialog_SelectAll_button); 
196
		fSelectAll.setFont(parent.getFont());
197
		setButtonLayoutData(fSelectAll);
198
		fSelectAll.addSelectionListener(new SelectionAdapter() {
199
			public void widgetSelected(SelectionEvent e) {
200
				selectAll();
201
			}
202
		});
203
		
204
		fDeselectAll= new Button(buttons, SWT.PUSH);
205
		fDeselectAll.setText(WorkingSetMessages.SimpleWorkingSetSelectionDialog_DeselectAll_button); 
206
		fDeselectAll.setFont(parent.getFont());
207
		setButtonLayoutData(fDeselectAll);
208
		fDeselectAll.addSelectionListener(new SelectionAdapter() {
209
			public void widgetSelected(SelectionEvent e) {
210
				deselectAll();
211
			}
212
		});
213
	}
214
	
215
	private void checkedStateChanged() {
216
		List elements= Arrays.asList(fTableViewer.getCheckedElements());
217
		fSelectedWorkingSets= (IWorkingSet[])elements.toArray(new IWorkingSet[elements.size()]);
218
	}
219
	
220
	private void selectAll() {
221
		fTableViewer.setAllChecked(true);
222
		checkedStateChanged();
223
	}
224
	
225
	private void deselectAll() {
226
		fTableViewer.setAllChecked(false);
227
		checkedStateChanged();
228
	}
229
}
(-)ui/org/eclipse/jdt/internal/ui/workingsets/WorkingSetConfigurationBlock.java (+149 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 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
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.workingsets;
12
13
import org.eclipse.core.runtime.Assert;
14
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.events.SelectionAdapter;
17
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.graphics.FontMetrics;
19
import org.eclipse.swt.graphics.GC;
20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.widgets.Button;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.swt.widgets.Text;
26
27
import org.eclipse.jface.dialogs.Dialog;
28
import org.eclipse.jface.dialogs.IDialogConstants;
29
import org.eclipse.jface.resource.JFaceResources;
30
import org.eclipse.jface.window.Window;
31
32
import org.eclipse.ui.IWorkingSet;
33
import org.eclipse.ui.IWorkingSetManager;
34
import org.eclipse.ui.PlatformUI;
35
36
37
public class WorkingSetConfigurationBlock {
38
	
39
	private Label fLabel;
40
	private Text fText;
41
	private Button fConfigure;
42
	private IWorkingSet[] fSelectedWorkingSets;
43
	private String[] fWorkingSetIDs;
44
	private String fMessage;
45
46
	/**
47
	 * @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>
49
	 */
50
	public WorkingSetConfigurationBlock(IWorkingSet[] preSelectedWorkingSets, String[] compatibleWorkingSetIds) {
51
		Assert.isNotNull(preSelectedWorkingSets);
52
		Assert.isNotNull(compatibleWorkingSetIds);
53
		
54
		fSelectedWorkingSets= preSelectedWorkingSets;
55
		fWorkingSetIDs= compatibleWorkingSetIds;
56
	}
57
	
58
	/**
59
	 * @param message the message to show to the user in the working set selection dialog
60
	 */
61
	public void setDialogMessage(String message) {
62
		fMessage= message;
63
	}
64
	
65
	/**
66
	 * @return the selected working sets, not <b>null</b>
67
	 */
68
	public IWorkingSet[] getSelectedWorkingSets() {
69
		return fSelectedWorkingSets;
70
	}
71
72
	/**
73
	 * Add this block to the <code>parent</parent>
74
	 * @param parent the parent to add the block to, not <b>null</b>
75
	 */
76
	public void createContent(final Composite parent) {
77
		int numColumn= 3;
78
		
79
		Composite composite= new Composite(parent, SWT.NONE);
80
		composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
81
		composite.setLayout(new GridLayout(numColumn, false));
82
					
83
		fLabel= new Label(composite, SWT.NONE);
84
		fLabel.setText(WorkingSetMessages.WorkingSetConfigurationBlock_WorkingSetText_name);
85
		
86
		fText= new Text(composite, SWT.READ_ONLY | SWT.BORDER);
87
		GridData textData= new GridData(SWT.FILL, SWT.CENTER, true, false);
88
		textData.horizontalSpan= numColumn - 2;
89
		textData.horizontalIndent= 0;
90
		fText.setLayoutData(textData);
91
		
92
		fConfigure= new Button(composite, SWT.PUSH);
93
		fConfigure.setText(WorkingSetMessages.WorkingSetConfigurationBlock_SelectWorkingSet_button);
94
		GridData configureData= new GridData(SWT.LEFT, SWT.CENTER, false, false);
95
		configureData.widthHint= getButtonWidthHint(fConfigure);
96
		fConfigure.setLayoutData(configureData);
97
		fConfigure.addSelectionListener(new SelectionAdapter() {
98
99
			public void widgetSelected(SelectionEvent e) {
100
				IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
101
				IWorkingSet[] workingSets= manager.getWorkingSets();
102
				SimpleWorkingSetSelectionDialog dialog= new SimpleWorkingSetSelectionDialog(parent.getShell(), workingSets, fWorkingSetIDs);
103
				dialog.setSelection(fSelectedWorkingSets);
104
				if (fMessage != null)
105
					dialog.setMessage(fMessage);
106
107
				if (dialog.open() == Window.OK) {
108
					IWorkingSet[] result= dialog.getSelection();
109
					if (result != null && result.length > 0) {
110
						fSelectedWorkingSets= result;
111
						manager.addRecentWorkingSet(result[0]);
112
					} else {
113
						fSelectedWorkingSets= new IWorkingSet[0];
114
					}
115
					updateWorkingSetSelection();
116
				}
117
			}
118
		});
119
		
120
		updateWorkingSetSelection();
121
	}
122
	
123
	private void updateWorkingSetSelection() {
124
		StringBuffer buf= new StringBuffer();
125
		
126
		if (fSelectedWorkingSets.length > 0) {
127
			buf.append(fSelectedWorkingSets[0].getLabel());
128
			for (int i= 1; i < fSelectedWorkingSets.length; i++) {
129
				IWorkingSet ws= fSelectedWorkingSets[i];
130
				buf.append(',').append(' ');
131
				buf.append(ws.getLabel());
132
			}
133
		}
134
		
135
		fText.setText(buf.toString());
136
	}
137
	
138
	private static int getButtonWidthHint(Button button) {
139
		button.setFont(JFaceResources.getDialogFont());
140
		
141
		GC gc = new GC(button);
142
		gc.setFont(button.getFont());
143
		FontMetrics fontMetrics= gc.getFontMetrics();
144
		gc.dispose();
145
		
146
		int widthHint= Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.BUTTON_WIDTH);
147
		return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
148
	}
149
}

Return to bug 150009