1
/*******************************************************************************
2
* Copyright (c) 2004, 2008 QNX Software Systems 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
9
* QNX Software Systems - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
13
import java.util.ArrayList;
15
import org.eclipse.cdt.core.model.CoreModel;
16
import org.eclipse.cdt.core.model.ICProject;
17
import org.eclipse.cdt.core.model.IContainerEntry;
18
import org.eclipse.cdt.core.model.IPathEntry;
19
import org.eclipse.cdt.internal.ui.CPluginImages;
20
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
21
import org.eclipse.cdt.internal.ui.wizards.NewElementWizardPage;
22
import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField;
23
import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
24
import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil;
25
import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField;
26
import org.eclipse.cdt.ui.wizards.IPathEntryContainerPage;
27
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.core.runtime.Path;
29
import org.eclipse.jface.dialogs.Dialog;
30
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.layout.GridLayout;
32
import org.eclipse.swt.widgets.Composite;
36
public class CPathContainerDefaultPage extends NewElementWizardPage implements IPathEntryContainerPage {
38
private StringDialogField fEntryField;
39
private ArrayList<IPath> fUsedPaths;
42
* Constructor for ClasspathContainerDefaultPage.
44
public CPathContainerDefaultPage() {
45
super("CPathContainerDefaultPage"); //$NON-NLS-1$
46
setTitle(CPathEntryMessages.CPathContainerDefaultPage_title);
47
setDescription(CPathEntryMessages.CPathContainerDefaultPage_description);
48
setImageDescriptor(CPluginImages.DESC_WIZBAN_ADD_LIBRARY);
50
fUsedPaths= new ArrayList<IPath>();
52
fEntryField= new StringDialogField();
53
fEntryField.setLabelText(CPathEntryMessages.CPathContainerDefaultPage_path_label);
54
fEntryField.setDialogFieldListener(new IDialogFieldListener() {
55
public void dialogFieldChanged(DialogField field) {
62
protected void validatePath() {
63
StatusInfo status= new StatusInfo();
64
String str= fEntryField.getText();
65
if (str.length() == 0) {
66
status.setError(CPathEntryMessages.CPathContainerDefaultPage_path_error_enterpath);
67
} else if (!Path.ROOT.isValidPath(str)) {
68
status.setError(CPathEntryMessages.CPathContainerDefaultPage_path_error_invalidpath);
70
IPath path= new Path(str);
71
if (path.segmentCount() == 0) {
72
status.setError(CPathEntryMessages.CPathContainerDefaultPage_path_error_needssegment);
73
} else if (fUsedPaths.contains(path)) {
74
status.setError(CPathEntryMessages.CPathContainerDefaultPage_path_error_alreadyexists);
81
* @see IDialogPage#createControl(Composite)
83
public void createControl(Composite parent) {
84
Composite composite= new Composite(parent, SWT.NONE);
85
GridLayout layout= new GridLayout();
87
composite.setLayout(layout);
89
fEntryField.doFillIntoGrid(composite, 2);
90
LayoutUtil.setHorizontalGrabbing(fEntryField.getTextControl(null));
92
fEntryField.setFocus();
94
setControl(composite);
95
Dialog.applyDialogFont(composite);
96
// WorkbenchHelp.setHelp(composite, IJavaHelpContextIds.CLASSPATH_CONTAINER_DEFAULT_PAGE);
100
* @see IClasspathContainerPage#finish()
102
public boolean finish() {
107
* @see IClasspathContainerPage#getSelection()
109
public IContainerEntry[] getNewContainers() {
110
return new IContainerEntry[] {CoreModel.newContainerEntry(new Path(fEntryField.getText()))};
114
* @see org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension#initialize(org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.core.IClasspathEntry)
116
public void initialize(ICProject project, IPathEntry[] currentEntries) {
117
for (int i= 0; i < currentEntries.length; i++) {
118
IPathEntry curr= currentEntries[i];
119
if (curr.getEntryKind() == IPathEntry.CDT_CONTAINER) {
120
fUsedPaths.add(curr.getPath());
126
* @see IClasspathContainerPage#setSelection(IClasspathEntry)
128
public void setSelection(IContainerEntry containerEntry) {
129
if (containerEntry != null) {
130
fUsedPaths.remove(containerEntry.getPath());
131
fEntryField.setText(containerEntry.getPath().toString());
133
fEntryField.setText(""); //$NON-NLS-1$