~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathContainerDefaultPage.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
7
 
 *
8
 
 * Contributors:
9
 
 *     QNX Software Systems - initial API and implementation
10
 
 *******************************************************************************/
11
 
package org.eclipse.cdt.internal.ui.dialogs.cpaths;
12
 
 
13
 
import java.util.ArrayList;
14
 
 
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;
33
 
 
34
 
/**
35
 
 */
36
 
public class CPathContainerDefaultPage extends NewElementWizardPage implements IPathEntryContainerPage {
37
 
 
38
 
        private StringDialogField fEntryField;
39
 
        private ArrayList<IPath> fUsedPaths;
40
 
 
41
 
        /**
42
 
         * Constructor for ClasspathContainerDefaultPage.
43
 
         */
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);
49
 
                
50
 
                fUsedPaths= new ArrayList<IPath>();
51
 
                
52
 
                fEntryField= new StringDialogField();
53
 
                fEntryField.setLabelText(CPathEntryMessages.CPathContainerDefaultPage_path_label); 
54
 
                fEntryField.setDialogFieldListener(new IDialogFieldListener() {
55
 
                        public void dialogFieldChanged(DialogField field) {
56
 
                                validatePath();
57
 
                        }
58
 
                });
59
 
                validatePath();
60
 
        }
61
 
 
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); 
69
 
                } else {
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); 
75
 
                        }
76
 
                }
77
 
                updateStatus(status);
78
 
        }
79
 
 
80
 
        /* (non-Javadoc)
81
 
         * @see IDialogPage#createControl(Composite)
82
 
         */
83
 
        public void createControl(Composite parent) {
84
 
                Composite composite= new Composite(parent, SWT.NONE);
85
 
                GridLayout layout= new GridLayout();
86
 
                layout.numColumns= 1;
87
 
                composite.setLayout(layout);
88
 
                
89
 
                fEntryField.doFillIntoGrid(composite, 2);
90
 
                LayoutUtil.setHorizontalGrabbing(fEntryField.getTextControl(null));
91
 
                
92
 
                fEntryField.setFocus();
93
 
                
94
 
                setControl(composite);
95
 
                Dialog.applyDialogFont(composite);
96
 
//              WorkbenchHelp.setHelp(composite, IJavaHelpContextIds.CLASSPATH_CONTAINER_DEFAULT_PAGE);
97
 
        }
98
 
 
99
 
        /* (non-Javadoc)
100
 
         * @see IClasspathContainerPage#finish()
101
 
         */
102
 
        public boolean finish() {
103
 
                return true;
104
 
        }
105
 
        
106
 
        /* (non-Javadoc)
107
 
         * @see IClasspathContainerPage#getSelection()
108
 
         */
109
 
        public IContainerEntry[] getNewContainers() {
110
 
                return new IContainerEntry[] {CoreModel.newContainerEntry(new Path(fEntryField.getText()))};
111
 
        }
112
 
        
113
 
        /* (non-Javadoc)
114
 
         * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension#initialize(org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.core.IClasspathEntry)
115
 
         */
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());
121
 
                        }
122
 
                }
123
 
        }               
124
 
 
125
 
        /* (non-Javadoc)
126
 
         * @see IClasspathContainerPage#setSelection(IClasspathEntry)
127
 
         */
128
 
        public void setSelection(IContainerEntry containerEntry) {
129
 
                if (containerEntry != null) {
130
 
                        fUsedPaths.remove(containerEntry.getPath());
131
 
                        fEntryField.setText(containerEntry.getPath().toString());
132
 
                } else {
133
 
                        fEntryField.setText(""); //$NON-NLS-1$
134
 
                }
135
 
        }
136
 
}