]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/AccessRuleEntryDialog.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui / org / eclipse / jdt / internal / ui / wizards / buildpaths / AccessRuleEntryDialog.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 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 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.wizards.buildpaths;
12
13import org.eclipse.swt.SWT;
14import org.eclipse.swt.layout.GridData;
15import org.eclipse.swt.layout.GridLayout;
16import org.eclipse.swt.widgets.Composite;
17import org.eclipse.swt.widgets.Control;
18import org.eclipse.swt.widgets.Label;
19import org.eclipse.swt.widgets.Shell;
20
21import org.eclipse.core.runtime.IPath;
22import org.eclipse.core.runtime.Path;
23
24import org.eclipse.jface.dialogs.StatusDialog;
25
26import org.eclipse.ui.PlatformUI;
27
28import org.eclipse.jdt.core.IAccessRule;
29import org.eclipse.jdt.core.JavaCore;
30
31import org.eclipse.jdt.internal.corext.util.Messages;
32
33import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
34import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
35import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
36import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
37import org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField;
38import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
39import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
40import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
41
42public class AccessRuleEntryDialog extends StatusDialog {
43
44 private StringDialogField fPatternDialog;
45 private StatusInfo fPatternStatus;
46
47 private String fPattern;
48 private ComboDialogField fRuleKindCombo;
49 private int[] fRuleKinds;
50
51 public AccessRuleEntryDialog(Shell parent, IAccessRule ruleToEdit, CPListElement entryToEdit) {
52 super(parent);
53
54 String 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, BasicElementLabels.getPathLabel(entryToEdit.getPath(), false));
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[] 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 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
102 * @since 3.4
103 */
104 @Override
105 protected boolean isResizable() {
106 return true;
107 }
108
109 @Override
110 protected Control createDialogArea(Composite parent) {
111 Composite composite= (Composite) super.createDialogArea(parent);
112
113 Composite inner= new Composite(composite, SWT.NONE);
114 GridLayout layout= new GridLayout();
115 layout.marginHeight= 0;
116 layout.marginWidth= 0;
117 layout.numColumns= 2;
118 inner.setLayout(layout);
119 inner.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
120
121 Label description= new Label(inner, SWT.WRAP);
122 description.setText(NewWizardMessages.TypeRestrictionEntryDialog_description);
123
124 GridData gd= new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
125 gd.widthHint= convertWidthInCharsToPixels(60);
126 description.setLayoutData(gd);
127
128 fRuleKindCombo.doFillIntoGrid(inner, 2);
129 fPatternDialog.doFillIntoGrid(inner, 2);
130
131 Label description2= new Label(inner, SWT.WRAP);
132 description2.setText(NewWizardMessages.TypeRestrictionEntryDialog_description2);
133
134 gd= new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1);
135 gd.widthHint= convertWidthInCharsToPixels(60);
136 description2.setLayoutData(gd);
137
138 fPatternDialog.postSetFocusOnDialogField(parent.getDisplay());
139 applyDialogFont(composite);
140 return composite;
141 }
142
143
144 // -------- TypeRulesAdapter --------
145
146 private class TypeRulesAdapter implements IDialogFieldListener {
147
148 public void dialogFieldChanged(DialogField field) {
149 doStatusLineUpdate();
150 }
151 }
152
153
154 protected void doStatusLineUpdate() {
155 checkIfPatternValid();
156 updateStatus(fPatternStatus);
157 }
158
159 protected void checkIfPatternValid() {
160 String pattern= fPatternDialog.getText().trim();
161 if (pattern.length() == 0) {
162 fPatternStatus.setError(NewWizardMessages.TypeRestrictionEntryDialog_error_empty);
163 return;
164 }
165 IPath path= new Path(pattern);
166 if (path.isAbsolute() || path.getDevice() != null) {
167 fPatternStatus.setError(NewWizardMessages.TypeRestrictionEntryDialog_error_notrelative);
168 return;
169 }
170
171 fPattern= pattern;
172 fPatternStatus.setOK();
173 }
174
175 public IAccessRule getRule() {
176 IPath filePattern= new Path(fPattern);
177 int kind= fRuleKinds[fRuleKindCombo.getSelectionIndex()];
178 return JavaCore.newAccessRule(filePattern, kind);
179 }
180
181 /*
182 * @see org.eclipse.jface.window.Window#configureShell(Shell)
183 */
184 @Override
185 protected void configureShell(Shell newShell) {
186 super.configureShell(newShell);
187 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.ACCESS_RULES_DIALOG);
188 }
189}