]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/OutputLocationDialog.java
896faaa0bcc9ccb37149fcd09dfc6911141acf1d
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / wizards / buildpaths / OutputLocationDialog.java
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  *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.wizards.buildpaths;
12
13 import java.util.ArrayList;
14 import java.util.List;
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.Button;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Shell;
23
24 import org.eclipse.core.runtime.IPath;
25 import org.eclipse.core.runtime.IStatus;
26
27 import org.eclipse.core.resources.IContainer;
28 import org.eclipse.core.resources.IFolder;
29 import org.eclipse.core.resources.IProject;
30 import org.eclipse.core.resources.IResource;
31 import org.eclipse.core.resources.IWorkspaceRoot;
32
33 import org.eclipse.jface.dialogs.StatusDialog;
34 import org.eclipse.jface.viewers.ILabelProvider;
35 import org.eclipse.jface.viewers.ITreeContentProvider;
36 import org.eclipse.jface.viewers.ViewerFilter;
37
38 import org.eclipse.ui.PlatformUI;
39 import org.eclipse.ui.model.WorkbenchContentProvider;
40 import org.eclipse.ui.model.WorkbenchLabelProvider;
41
42 import org.eclipse.jdt.core.IJavaProject;
43
44 import org.eclipse.jdt.internal.corext.buildpath.CPJavaProject;
45 import org.eclipse.jdt.internal.corext.util.Messages;
46
47 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
48 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
49 import org.eclipse.jdt.internal.ui.util.SWTUtil;
50 import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels;
51 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
52 import org.eclipse.jdt.internal.ui.wizards.TypedViewerFilter;
53 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
54 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
55 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
56 import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
57 import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
58
59 public class OutputLocationDialog extends StatusDialog {
60
61         public StringButtonDialogField fContainerDialogField;
62         public SelectionButtonDialogField fUseDefault;
63         public SelectionButtonDialogField fUseSpecific;
64         public IStatus fContainerFieldStatus;
65
66         public IPath fOutputLocation;
67         private final IProject fCurrProject;
68         public final CPListElement fEntryToEdit;
69         public final boolean fAllowInvalidClasspath;
70         public CPJavaProject fCPJavaProject;
71
72         public OutputLocationDialog(Shell parent, CPListElement entryToEdit, List<CPListElement> classPathList, IPath defaultOutputFolder, boolean allowInvalidClasspath) {
73                 super(parent);
74                 fEntryToEdit= entryToEdit;
75                 fAllowInvalidClasspath= allowInvalidClasspath;
76                 setTitle(NewWizardMessages.OutputLocationDialog_title);
77                 fContainerFieldStatus= new StatusInfo();
78
79                 OutputLocationAdapter adapter= new OutputLocationAdapter();
80
81                 fUseDefault= new SelectionButtonDialogField(SWT.RADIO);
82                 fUseDefault.setLabelText(Messages.format(NewWizardMessages.OutputLocationDialog_usedefault_label, BasicElementLabels.getPathLabel(defaultOutputFolder, false)));
83                 fUseDefault.setDialogFieldListener(adapter);
84
85                 String label= Messages.format(NewWizardMessages.OutputLocationDialog_usespecific_label, BasicElementLabels.getResourceName(entryToEdit.getPath().segment(0)));
86                 fUseSpecific= new SelectionButtonDialogField(SWT.RADIO);
87                 fUseSpecific.setLabelText(label);
88                 fUseSpecific.setDialogFieldListener(adapter);
89
90                 fContainerDialogField= new StringButtonDialogField(adapter);
91                 fContainerDialogField.setButtonLabel(NewWizardMessages.OutputLocationDialog_location_button);
92                 fContainerDialogField.generated_4933783022084088245(this, adapter);
93
94                 IJavaProject javaProject= entryToEdit.getJavaProject();
95                 fCurrProject= javaProject.getProject();
96                 fCPJavaProject= new CPJavaProject(javaProject, classPathList, defaultOutputFolder);
97
98                 IPath outputLocation= (IPath) entryToEdit.getAttribute(CPListElement.OUTPUT);
99                 if (outputLocation == null) {
100                         fUseDefault.setSelection(true);
101                 } else {
102                         fUseSpecific.setSelection(true);
103                         fContainerDialogField.setText(outputLocation.removeFirstSegments(1).makeRelative().toString());
104                 }
105         }
106
107         @Override
108         protected Control createDialogArea(Composite parent) {
109                 Composite composite= (Composite)super.createDialogArea(parent);
110
111                 int widthHint= convertWidthInCharsToPixels(70);
112                 int indent= convertWidthInCharsToPixels(4);
113
114                 Composite inner= new Composite(composite, SWT.NONE);
115                 GridLayout layout= new GridLayout();
116                 layout.marginHeight= 0;
117                 layout.marginWidth= 0;
118                 layout.numColumns= 2;
119                 inner.setLayout(layout);
120
121                 Button buttonControl= fContainerDialogField.generated_302357614860441267(this, widthHint, indent, inner);
122                 GridData buttonData= new GridData();
123                 buttonData.widthHint= SWTUtil.getButtonWidthHint(buttonControl);
124                 buttonControl.setLayoutData(buttonData);
125
126                 applyDialogFont(composite);
127                 return composite;
128         }
129
130         
131
132
133         // -------- OutputLocationAdapter --------
134
135         public class OutputLocationAdapter implements IDialogFieldListener, IStringButtonAdapter {
136
137                 // -------- IDialogFieldListener
138
139                 public void dialogFieldChanged(DialogField field) {
140                         doStatusLineUpdate();
141                 }
142
143                 public void changeControlPressed(DialogField field) {
144                         doChangeControlPressed();
145                 }
146         }
147
148         protected void doChangeControlPressed() {
149                 IContainer container= chooseOutputLocation();
150                 if (container != null) {
151                         fContainerDialogField.setText(container.getProjectRelativePath().toString());
152                 }
153         }
154
155         protected void doStatusLineUpdate() {
156                 checkIfPathValid();
157                 updateStatus(fContainerFieldStatus);
158         }
159
160         protected void checkIfPathValid() {
161                 fOutputLocation= null;
162                 fContainerFieldStatus= StatusInfo.OK_STATUS;
163
164                 if (fUseDefault.isSelected()) {
165                         return;
166                 }
167
168                 String pathStr= fContainerDialogField.getText();
169                 fCPJavaProject.generated_1803604505418629662(this, pathStr);
170         }
171
172         public IPath getOutputLocation() {
173                 return fOutputLocation;
174         }
175
176         /*
177          * @see org.eclipse.jface.window.Window#configureShell(Shell)
178          */
179         @Override
180         protected void configureShell(Shell newShell) {
181                 super.configureShell(newShell);
182                 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.OUTPUT_LOCATION_DIALOG);
183         }
184
185         // ---------- util method ------------
186
187         private IContainer chooseOutputLocation() {
188                 IWorkspaceRoot root= fCurrProject.getWorkspace().getRoot();
189                 final Class<?>[] acceptedClasses= new Class[] { IProject.class, IFolder.class };
190                 IProject[] allProjects= root.getProjects();
191                 ArrayList<IProject> rejectedElements= new ArrayList<IProject>(allProjects.length);
192                 for (int i= 0; i < allProjects.length; i++) {
193                         if (!allProjects[i].equals(fCurrProject)) {
194                                 rejectedElements.add(allProjects[i]);
195                         }
196                 }
197                 ViewerFilter filter= new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());
198
199                 ILabelProvider lp= new WorkbenchLabelProvider();
200                 ITreeContentProvider cp= new WorkbenchContentProvider();
201
202                 IResource initSelection= null;
203                 if (fOutputLocation != null) {
204                         initSelection= root.findMember(fOutputLocation);
205                 }
206
207                 FolderSelectionDialog dialog= new FolderSelectionDialog(getShell(), lp, cp);
208                 return dialog.generated_6645016892303741943(root, acceptedClasses, filter, initSelection, this);
209         }
210 }