Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1bb75ad74e281f8e382cdc8ad04583cc72159e92 (plain) (blame)
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
package org.eclipse.cdt.managedbuilder.ui.properties;

/*******************************************************************************
 * Copyright (c) 2002,2004 IBM Corporation and others. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Common Public License v0.5 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: IBM Rational Software - Initial API and implementation
 ******************************************************************************/

import org.eclipse.cdt.internal.ui.dialogs.SelectionStatusDialog;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;

/**
 * The BrowseEntryDialog allows clients to prompt the user for a path location.
 * The dialog will contain a browse button to make it easy to lcate absolute
 * locations onthe target file system. The user will also be able to specify a
 * location using defined variables. The client must be able to deal with these
 * variables.
 */
public class BrowseEntryDialog extends SelectionStatusDialog {
	// String constants
	private static final String PREFIX = "BuildPropertyCommon"; //$NON-NLS-1$
	private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$
	private static final String BROWSE = LABEL + ".browse"; //$NON-NLS-1$
	private static final String HIDE = "hideAdvanced"; //$NON-NLS-1$
	private static final String SHOW = "showAdvanced"; //$NON-NLS-1$
	private static final String EMPTY = "NewFolderDialog.folderNameEmpty"; //$NON-NLS-1$
	
	/* (non-Javadoc)
	 * The title of the dialog.
	 */
	private String title = "";

	/* (non-Javadoc)
	 * The message to display, or <code>null</code> if none.
	 */
	private String message = "";

	/* (non-Javadoc)
	 * The input value; the empty string by default.
	 */
	private String folderName = "";
	
	/* (non-Javadoc)
	 * 
	 */
	private int basicShellHeight;
	
	/* (non-Javadoc)
	 * 
	 */
//	private CreateLinkedResourceGroup linkedResourceGroup;

	// Widgets
	private Button advancedButton = null;
	private Button browseButton = null;
	private Label errorMessageLabel;
	private Composite macroComposite;
	private Text text = null;

	/**
	 * Creates an input dialog with OK, Cancel, a Browse button and a button to
	 * reveal path macros.
	 * 
	 * @param shell
	 *            the parent shell
	 * @param dialogTitle
	 *            the title of the dialog or <code>null</code> if none
	 * @param dialogMessage
	 *            the dialog message, or <code>null</code> if none
	 * @param initialValue
	 *            the initial input value, or <code>null</code> if none
	 *            (equivalent to the empty string)
	 */
	public BrowseEntryDialog(Shell shell, String dialogTitle, String dialogMessage, String initialValue) {
		super(shell);
		// We are editing the value argument if it is not an empty string
		if (dialogTitle != null) {
			title = dialogTitle;
		}
		// Cache the message to be shown in the label
		if (dialogMessage != null) {
			message = dialogMessage;
		}
		// Value for the text widget
		if (initialValue != null) {
			folderName = initialValue;
		}
		setStatusLineAboveButtons(true);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.internal.ui.dialogs.SelectionStatusDialog#computeResult()
	 */
	protected void computeResult() {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.internal.ui.dialogs.SelectionStatusDialog#configureShell(org.eclipse.swt.widgets.Shell)
	 */
	protected void configureShell(Shell shell) {
		super.configureShell(shell);
		// Set the display title the user has specified
		if (title != null) {
			shell.setText(title);
		}
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.cdt.internal.ui.dialogs.SelectionStatusDialog#create()
	 */
	public void create() {
		// Disable the OK button to start
		super.create();
		getButton(IDialogConstants.OK_ID).setEnabled(false);
	}
	
	/* (non-Javadoc)
	 * 
	 * @param parent
	 */
	private void createAdvancedBrowseArea(Composite parent) {
		// Instantiate the macros button
		advancedButton = new Button(parent, SWT.PUSH);
		applyDialogFont(advancedButton);
		advancedButton.setText(IDEWorkbenchMessages.getString(SHOW));
		setButtonLayoutData(advancedButton);
		GridData data = (GridData) advancedButton.getLayoutData();
		data.horizontalAlignment = GridData.BEGINNING;
		advancedButton.setLayoutData(data);
		advancedButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				handleAdvancedPressed();
			}
		});
		advancedButton.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				advancedButton = null;
			}
		});
		
//		linkedResourceGroup = new CreateLinkedResourceGroup(
//				IResource.FOLDER, 
//				new Listener(){
//					public void handleEvent(Event event) {
//						// TODO Auto-generated method stub
//						
//					}
//				});
	}
	
	/* (non-Javadoc)
	 * 
	 * @param parent
	 */
	private void createBasicBrowseArea(Composite parent) {
		Composite basicGroup = new Composite(parent, SWT.NONE);
		basicGroup.setLayout(new GridLayout(2, false));
		basicGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		GridData data;
		// Create the label
		if (message != null) {
			Label label = new Label(basicGroup, SWT.WRAP);
			label.setText(message);
			data = new GridData(			
					GridData.FILL_HORIZONTAL |
					GridData.GRAB_VERTICAL |
					GridData.VERTICAL_ALIGN_BEGINNING);
			data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
			data.horizontalSpan = 2;
			label.setLayoutData(data);
			applyDialogFont(label);
		}

		// Entry widget next
		text = new Text(basicGroup, SWT.SINGLE | SWT.BORDER);
		data = new GridData(GridData.FILL_BOTH);
		data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
		text.setLayoutData(data);
		text.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				validateLocation();
			}
		});
		applyDialogFont(text);
		
		// Finally make the browse button
		browseButton = new Button(basicGroup, SWT.PUSH);
		applyDialogFont(browseButton);
		browseButton.setText(ManagedBuilderUIPlugin.getResourceString(BROWSE));
		setButtonLayoutData(browseButton);
		data = (GridData) browseButton.getLayoutData();
		data.horizontalAlignment = GridData.BEGINNING;
		browseButton.setLayoutData(data);
		browseButton.addSelectionListener(new SelectionAdapter () {
			public void widgetSelected(SelectionEvent e) {
				handleBrowsePressed();
			}
		});
		browseButton.addDisposeListener(new DisposeListener () {
			public void widgetDisposed(DisposeEvent e) {
				browseButton = null;
			}
		});
	}

	protected Control createDialogArea(Composite parent) {
		Composite composite = (Composite) super.createDialogArea(parent);
		composite.setLayout(new GridLayout());
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));

		createBasicBrowseArea(composite);
		createAdvancedBrowseArea(composite);
		
		return composite;
	}

	/**
	 * Answers the value the user has entered in the selection dialog. 
	 * 
	 * <p>The selection will be a folder location specified in the format appropriate 
	 * for the platform that Eclipse is running on, i.e. <code>C:\foo\mydir</code> 
	 * for Windows platforms and <code>/foo/mydir</code> on POSIX platforms.
	 * 
	 * <p>The answer may also contain a path variable as a component of the location. It 
	 * is the responsibility of the client to properly handle this situation.
	 *  
	 * @return String
	 */
	public String getValue() {
		return folderName;
	}

	/* (non-Javadoc)
	 * Shows/hides the path macro widgets.
	 */
	protected void handleAdvancedPressed() {
		Shell shell = getShell();
		Point shellSize = shell.getSize();

		if (macroComposite == null) {
			basicShellHeight = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).y;
			Composite composite = (Composite) getDialogArea();
//			macroComposite = linkedResourceGroup.createContents(composite);
			macroComposite = ControlFactory.createComposite(composite, 1);
			shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
			shell.setSize(shellSize);
			advancedButton.setText(IDEWorkbenchMessages.getString(HIDE)); 
		} else if (macroComposite.getVisible()) {
			macroComposite.setVisible(false);
			shell.setSize(shellSize.x, basicShellHeight);
			advancedButton.setText(IDEWorkbenchMessages.getString(SHOW));
		} else {
			macroComposite.setVisible(true);
			shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
			shell.setSize(shellSize);
			advancedButton.setText(IDEWorkbenchMessages.getString(HIDE));
		}
		
	}
	
	/* (non-Javadoc)
	 * 
	 */
	protected void handleBrowsePressed() {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * Utility method to send a status message to the status line of the dialog.
	 *   
	 * @param severity
	 * @param message
	 */
	private void updateStatus(int severity, String message) {
		updateStatus(new Status(severity, ManagedBuilderCorePlugin.getUniqueIdentifier(), severity, message, null));
	}

	/* (non-Javadoc)
	 * @see org.eclipse.cdt.internal.ui.dialogs.SelectionStatusDialog#updateStatus(org.eclipse.core.runtime.IStatus)
	 */
	protected void updateStatus(IStatus status) {
		// TODO Auto-generated method stub
		super.updateStatus(status);
	}

	/**
	 * 
	 */
	protected void validateLocation() {
		folderName = text.getText();
		// Empty or null string is invalid
		if (folderName == null || folderName.equals("")) {
			updateStatus(IStatus.ERROR, IDEWorkbenchMessages.getString(EMPTY));
			return;
		} else {
			// Make sure that the specified location exists
			IPath path = new Path(folderName);
			if (!path.isValidPath(folderName)) {
				updateStatus(IStatus.ERROR, "Folder name invalid");
				return;
			}
		}
		updateStatus(IStatus.OK, "");	//$NON-NLS-1$
		getButton(IDialogConstants.OK_ID).setEnabled(true);
	}
}

Back to the top