KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > wizards > buildpaths > AccessRuleEntryDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.internal.ui.wizards.buildpaths;
12
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.core.runtime.Path;
15
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Shell;
23
24 import org.eclipse.jface.dialogs.StatusDialog;
25
26 import org.eclipse.ui.PlatformUI;
27
28 import org.eclipse.jdt.core.IAccessRule;
29 import org.eclipse.jdt.core.JavaCore;
30
31 import org.eclipse.jdt.internal.corext.util.Messages;
32
33 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
34 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
35 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
36 import org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField;
37 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
38 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
39 import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
40
41 public class AccessRuleEntryDialog extends StatusDialog {
42     
43     private StringDialogField fPatternDialog;
44     private StatusInfo fPatternStatus;
45     
46     private String JavaDoc fPattern;
47     private ComboDialogField fRuleKindCombo;
48     private int[] fRuleKinds;
49         
50     public AccessRuleEntryDialog(Shell parent, IAccessRule ruleToEdit, CPListElement entryToEdit) {
51         super(parent);
52         setShellStyle(getShellStyle() | SWT.RESIZE);
53         
54         String JavaDoc title, message;
55         if (ruleToEdit == null) {
56             title= NewWizardMessages.TypeRestrictionEntryDialog_add_title;
57         } else {
58             title= NewWizardMessages.TypeRestrictionEntryDialog_edit_title;
59         }
60         message= Messages.format(NewWizardMessages.TypeRestrictionEntryDialog_pattern_label, entryToEdit.getPath().makeRelative().toString());
61         setTitle(title);
62         
63         fPatternStatus= new StatusInfo();
64         
65         TypeRulesAdapter adapter= new TypeRulesAdapter();
66         fPatternDialog= new StringDialogField();
67         fPatternDialog.setLabelText(message);
68         fPatternDialog.setDialogFieldListener(adapter);
69         
70         fRuleKindCombo= new ComboDialogField(SWT.READ_ONLY);
71         fRuleKindCombo.setLabelText(NewWizardMessages.TypeRestrictionEntryDialog_kind_label);
72         fRuleKindCombo.setDialogFieldListener(adapter);
73         String JavaDoc[] items= {
74                 NewWizardMessages.TypeRestrictionEntryDialog_kind_non_accessible,
75                 NewWizardMessages.TypeRestrictionEntryDialog_kind_discourraged,
76                 NewWizardMessages.TypeRestrictionEntryDialog_kind_accessible
77         };
78         fRuleKinds= new int[] {
79                 IAccessRule.K_NON_ACCESSIBLE,
80                 IAccessRule.K_DISCOURAGED,
81                 IAccessRule.K_ACCESSIBLE
82         };
83         fRuleKindCombo.setItems(items);
84         
85         
86         if (ruleToEdit == null) {
87             fPatternDialog.setText(""); //$NON-NLS-1$
88
fRuleKindCombo.selectItem(0);
89         } else {
90             fPatternDialog.setText(ruleToEdit.getPattern().toString());
91             for (int i= 0; i < fRuleKinds.length; i++) {
92                 if (fRuleKinds[i] == ruleToEdit.getKind()) {
93                     fRuleKindCombo.selectItem(i);
94                     break;
95                 }
96             }
97         }
98     }
99     
100     
101     protected Control createDialogArea(Composite parent) {
102         Composite composite= (Composite) super.createDialogArea(parent);
103                 
104         Composite inner= new Composite(composite, SWT.NONE);
105         GridLayout layout= new GridLayout();
106         layout.marginHeight= 0;
107         layout.marginWidth= 0;
108         layout.numColumns= 2;
109         inner.setLayout(layout);
110         inner.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
111         
112         Label description= new Label(inner, SWT.WRAP);
113         description.setText(NewWizardMessages.TypeRestrictionEntryDialog_description);
114
115         GridData gd= new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
116         gd.widthHint= convertWidthInCharsToPixels(60);
117         description.setLayoutData(gd);
118         
119         fRuleKindCombo.doFillIntoGrid(inner, 2);
120         fPatternDialog.doFillIntoGrid(inner, 2);
121                 
122         Label description2= new Label(inner, SWT.WRAP);
123         description2.setText(NewWizardMessages.TypeRestrictionEntryDialog_description2);
124
125         gd= new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
126         gd.widthHint= convertWidthInCharsToPixels(60);
127         description2.setLayoutData(gd);
128         
129         fPatternDialog.postSetFocusOnDialogField(parent.getDisplay());
130         applyDialogFont(composite);
131         return composite;
132     }
133
134         
135     // -------- TypeRulesAdapter --------
136

137     private class TypeRulesAdapter implements IDialogFieldListener {
138         
139         public void dialogFieldChanged(DialogField field) {
140             doStatusLineUpdate();
141         }
142     }
143     
144
145     protected void doStatusLineUpdate() {
146         checkIfPatternValid();
147         updateStatus(fPatternStatus);
148     }
149     
150     protected void checkIfPatternValid() {
151         String JavaDoc pattern= fPatternDialog.getText().trim();
152         if (pattern.length() == 0) {
153             fPatternStatus.setError(NewWizardMessages.TypeRestrictionEntryDialog_error_empty);
154             return;
155         }
156         IPath path= new Path(pattern);
157         if (path.isAbsolute() || path.getDevice() != null) {
158             fPatternStatus.setError(NewWizardMessages.TypeRestrictionEntryDialog_error_notrelative);
159             return;
160         }
161         
162         fPattern= pattern;
163         fPatternStatus.setOK();
164     }
165     
166     public IAccessRule getRule() {
167         IPath filePattern= new Path(fPattern);
168         int kind= fRuleKinds[fRuleKindCombo.getSelectionIndex()];
169         return JavaCore.newAccessRule(filePattern, kind);
170     }
171     
172     /*
173      * @see org.eclipse.jface.window.Window#configureShell(Shell)
174      */

175     protected void configureShell(Shell newShell) {
176         super.configureShell(newShell);
177         PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.ACCESS_RULES_DIALOG);
178     }
179 }
180
Popular Tags