Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2010 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.team.internal.ui.wizards; |
12 |
|
13 |
import java.util.ArrayList; |
14 |
import java.util.List; |
15 |
|
16 |
import org.eclipse.compare.internal.core.patch.DiffProject; |
17 |
import org.eclipse.compare.internal.patch.WorkspacePatcher; |
18 |
import org.eclipse.core.resources.IProject; |
19 |
import org.eclipse.core.resources.ResourcesPlugin; |
20 |
import org.eclipse.jface.viewers.*; |
21 |
import org.eclipse.jface.wizard.IWizardPage; |
22 |
import org.eclipse.jface.wizard.WizardPage; |
23 |
import org.eclipse.osgi.util.NLS; |
24 |
import org.eclipse.swt.SWT; |
25 |
import org.eclipse.swt.events.SelectionAdapter; |
26 |
import org.eclipse.swt.events.SelectionEvent; |
27 |
import org.eclipse.swt.graphics.Color; |
28 |
import org.eclipse.swt.graphics.Font; |
29 |
import org.eclipse.swt.layout.GridData; |
30 |
import org.eclipse.swt.layout.GridLayout; |
31 |
import org.eclipse.swt.widgets.*; |
32 |
import org.eclipse.team.internal.ui.TeamUIMessages; |
33 |
import org.eclipse.ui.model.WorkbenchLabelProvider; |
34 |
import org.eclipse.ui.views.navigator.ResourceComparator; |
35 |
|
36 |
public class PatchInaccessibleProjectsPage extends WizardPage { |
37 |
|
38 |
private CheckboxTableViewer checkList; |
39 |
private Button checkAllButton; |
40 |
private Button uncheckAllButton; |
41 |
|
42 |
private WorkspacePatcher fPatcher; |
43 |
|
44 |
public final static String PATCH_INACCESSIBLE_PROJECTS_NAME = "PatchInaccessibleProjectsPage"; //$NON-NLS-1$ |
45 |
|
46 |
public PatchInaccessibleProjectsPage(WorkspacePatcher patcher) { |
47 |
super(PATCH_INACCESSIBLE_PROJECTS_NAME, |
48 |
TeamUIMessages.PatchInaccessibleProjectsPage_title, null); |
49 |
setMessage(TeamUIMessages.PatchInaccessibleProjectsPage_message); |
50 |
fPatcher = patcher; |
51 |
} |
52 |
|
53 |
public void createControl(Composite parent) { |
54 |
initializeDialogUnits(parent); |
55 |
|
56 |
Composite composite = new Composite(parent, SWT.NULL); |
57 |
composite.setLayout(new GridLayout(3, false)); |
58 |
composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL |
59 |
| GridData.HORIZONTAL_ALIGN_FILL)); |
60 |
setControl(composite); |
61 |
Font parentFont = composite.getFont(); |
62 |
|
63 |
checkList = CheckboxTableViewer.newCheckList(composite, SWT.H_SCROLL |
64 |
| SWT.V_SCROLL | SWT.BORDER); |
65 |
checkList.setContentProvider(new ArrayContentProvider()); |
66 |
checkList.setLabelProvider(new WorkbenchLabelProvider() { |
67 |
public Color getForeground(Object element) { |
68 |
if (element instanceof IProject |
69 |
&& !((IProject) element).exists()) |
70 |
return Display.getCurrent().getSystemColor( |
71 |
SWT.COLOR_WIDGET_NORMAL_SHADOW); |
72 |
return super.getForeground(element); |
73 |
} |
74 |
|
75 |
protected String decorateText(String input, Object element) { |
76 |
if (element instanceof IProject |
77 |
&& !((IProject) element).exists()) |
78 |
return input |
79 |
+ NLS.bind( |
80 |
TeamUIMessages.PatchInaccessibleProjectsPage_projectDoesNotExistInWorkspace, |
81 |
""); //$NON-NLS-1$ |
82 |
return input; |
83 |
} |
84 |
}); |
85 |
checkList.addCheckStateListener(new ICheckStateListener() { |
86 |
public void checkStateChanged(CheckStateChangedEvent event) { |
87 |
IProject project = (IProject) event.getElement(); |
88 |
if (event.getChecked() && !project.exists()) |
89 |
checkList.setChecked(project, false); |
90 |
} |
91 |
}); |
92 |
checkList |
93 |
.setComparator(new ResourceComparator(ResourceComparator.NAME)); |
94 |
|
95 |
Table table = checkList.getTable(); |
96 |
GridData data = new GridData(GridData.VERTICAL_ALIGN_FILL |
97 |
| GridData.HORIZONTAL_ALIGN_FILL); |
98 |
data.horizontalSpan = 3; |
99 |
data.grabExcessHorizontalSpace = true; |
100 |
data.grabExcessVerticalSpace = true; |
101 |
table.setLayoutData(data); |
102 |
|
103 |
checkAllButton = new Button(composite, SWT.NONE); |
104 |
checkAllButton |
105 |
.setText(TeamUIMessages.PatchInaccessibleProjectsPage_selectExisting); |
106 |
checkAllButton.addSelectionListener(new SelectionAdapter() { |
107 |
public void widgetSelected(SelectionEvent e) { |
108 |
setAllChecked(true); |
109 |
} |
110 |
}); |
111 |
checkAllButton.setFont(parentFont); |
112 |
setButtonLayoutData(checkAllButton); |
113 |
|
114 |
uncheckAllButton = new Button(composite, SWT.NONE); |
115 |
uncheckAllButton |
116 |
.setText(TeamUIMessages.PatchInaccessibleProjectsPage_deselectAll); |
117 |
uncheckAllButton.addSelectionListener(new SelectionAdapter() { |
118 |
public void widgetSelected(SelectionEvent e) { |
119 |
setAllChecked(false); |
120 |
} |
121 |
}); |
122 |
uncheckAllButton.setFont(parentFont); |
123 |
setButtonLayoutData(uncheckAllButton); |
124 |
|
125 |
updateControls(); |
126 |
} |
127 |
|
128 |
private void updateControls() { |
129 |
DiffProject[] diffProjects = fPatcher.getDiffProjects(); |
130 |
List projects = new ArrayList(); |
131 |
if (diffProjects != null) { |
132 |
for (int i = 0; i < diffProjects.length; i++) { |
133 |
IProject project = ResourcesPlugin.getWorkspace().getRoot() |
134 |
.getProject(diffProjects[i].getName()); |
135 |
if (!project.isAccessible()) |
136 |
projects.add(project); |
137 |
} |
138 |
} |
139 |
checkList.setInput(projects.toArray(new IProject[] {})); |
140 |
} |
141 |
|
142 |
public void setVisible(boolean visible) { |
143 |
super.setVisible(visible); |
144 |
if (visible) |
145 |
updateControls(); |
146 |
} |
147 |
|
148 |
public IWizardPage getNextPage() { |
149 |
Object input = checkList.getInput(); |
150 |
// Skipping the patch parsed page in case this one is displayed |
151 |
if (input instanceof IProject[] && ((IProject[]) input).length > 0) |
152 |
return null; |
153 |
return super.getNextPage(); |
154 |
} |
155 |
|
156 |
public IProject[] getSelectedProjects() { |
157 |
Object elements[] = checkList.getCheckedElements(); |
158 |
List projects = new ArrayList(); |
159 |
for (int i = 0; i < elements.length; i++) |
160 |
projects.add(elements[i]); |
161 |
return (IProject[]) projects.toArray(new IProject[] {}); |
162 |
} |
163 |
|
164 |
private void setAllChecked(boolean checked) { |
165 |
int count = checkList.getTable().getItemCount(); |
166 |
for (int i = 0; i < count; i++) { |
167 |
IProject project = (IProject) checkList.getElementAt(i); |
168 |
if (project.exists()) |
169 |
checkList.setChecked(project, checked); |
170 |
} |
171 |
} |
172 |
|
173 |
} |