1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/*******************************************************************************
* Copyright (c) 2000, 2009 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 Corporation - initial API and implementation
* Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog
* font should be activated and used by other components.
* Red Hat Inc. - modified this file to work with ChangeLog Plugin
*******************************************************************************/
package org.eclipse.linuxtools.internal.changelog.core.actions;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.IPath;
import org.eclipse.linuxtools.internal.changelog.core.Messages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ISelectionValidator;
import org.eclipse.ui.dialogs.SelectionDialog;
/**
* A standard selection dialog which solicits a container resource from the user.
* The <code>getResult</code> method returns the selected container resource.
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
* <p>
* Example:
* <pre>
* ContainerSelectionDialog dialog =
* new ContainerSelectionDialog(getShell(), initialSelection, allowNewContainerName(), msg);
* dialog.open();
* Object[] result = dialog.getResult();
* </pre>
* </p>
* @noextend This class is not intended to be subclassed by clients.
*/
public class ChangeLogContainerSelectionDialog extends SelectionDialog {
/**
*
*/
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
private static final String ContainerSelectionDialog_title = Messages.getString("ChangeLogContainerSelectionDialog.Title"); //$NON-NLS-1$
private static final String ContainerSelectionDialog_message = Messages.getString("ChangeLogContainerSelectionDialog.Message"); //$NON-NLS-1$
private static final String CONTAINER_SELECTION_DIALOG = "org.eclipse.ui.ide.container_selection_dialog_context"; //$NON-NLS-1$
// the widget group;
ChangeLogContainerSelectionGroup group;
// the root resource to populate the viewer with
private IContainer initialSelection;
// allow the user to type in a new container name
private boolean allowNewContainerName = true;
// the validation message
Label statusMessage;
//for validating the selection
ISelectionValidator validator;
// show closed projects by default
private boolean showClosedProjects = true;
/**
* Creates a resource container selection dialog rooted at the given resource.
* All selections are considered valid.
*
* @param parentShell the parent shell
* @param initialRoot the initial selection in the tree
* @param allowNewContainerName <code>true</code> to enable the user to type in
* a new container name, and <code>false</code> to restrict the user to just
* selecting from existing ones
* @param message the message to be displayed at the top of this dialog, or
* <code>null</code> to display a default message
*/
public ChangeLogContainerSelectionDialog(Shell parentShell, IContainer initialRoot,
boolean allowNewContainerName, String message) {
super(parentShell);
setTitle(ContainerSelectionDialog_title);
this.initialSelection = initialRoot;
this.allowNewContainerName = allowNewContainerName;
if (message != null) {
setMessage(message);
} else {
setMessage(ContainerSelectionDialog_message);
}
setShellStyle(getShellStyle() | SWT.SHEET);
}
/* (non-Javadoc)
* Method declared in Window.
*/
@Override
protected void configureShell(Shell shell) {
super.configureShell(shell);
PlatformUI.getWorkbench().getHelpSystem()
.setHelp(shell, CONTAINER_SELECTION_DIALOG);
}
/* (non-Javadoc)
* Method declared on Dialog.
*/
@Override
protected Control createDialogArea(Composite parent) {
// create composite
Composite area = (Composite) super.createDialogArea(parent);
Listener listener = new Listener() {
public void handleEvent(Event event) {
if (statusMessage != null && validator != null) {
String errorMsg = validator.isValid(group
.getContainerFullPath());
if (errorMsg == null || errorMsg.equals(EMPTY_STRING)) {
statusMessage.setText(EMPTY_STRING);
getOkButton().setEnabled(true);
} else {
statusMessage.setText(errorMsg);
getOkButton().setEnabled(false);
}
}
}
};
// container selection group
group = new ChangeLogContainerSelectionGroup(area, listener,
allowNewContainerName, getMessage(), showClosedProjects, initialSelection);
if (initialSelection != null) {
group.setSelectedContainer(initialSelection);
}
statusMessage = new Label(area, SWT.WRAP);
statusMessage.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
statusMessage.setText(" \n "); //$NON-NLS-1$
statusMessage.setFont(parent.getFont());
return dialogArea;
}
/**
* The <code>ContainerSelectionDialog</code> implementation of this
* <code>Dialog</code> method builds a list of the selected resource containers
* for later retrieval by the client and closes this dialog.
*/
@Override
protected void okPressed() {
List<IPath> chosenContainerPathList = new ArrayList<IPath>();
IPath returnValue = group.getContainerFullPath();
if (returnValue != null) {
chosenContainerPathList.add(returnValue);
}
setResult(chosenContainerPathList);
super.okPressed();
}
/**
* Sets the validator to use.
*
* @param validator A selection validator
*/
public void setValidator(ISelectionValidator validator) {
this.validator = validator;
}
/**
* Set whether or not closed projects should be shown
* in the selection dialog.
*
* @param show Whether or not to show closed projects.
*/
public void showClosedProjects(boolean show) {
this.showClosedProjects = show;
}
}
|