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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.wizards.buildpaths;
13 import java.util.ArrayList;
14 import java.util.List;
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;
24 import org.eclipse.core.runtime.IPath;
25 import org.eclipse.core.runtime.IStatus;
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;
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;
38 import org.eclipse.ui.PlatformUI;
39 import org.eclipse.ui.model.WorkbenchContentProvider;
40 import org.eclipse.ui.model.WorkbenchLabelProvider;
42 import org.eclipse.jdt.core.IJavaProject;
44 import org.eclipse.jdt.internal.corext.buildpath.CPJavaProject;
45 import org.eclipse.jdt.internal.corext.util.Messages;
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;
59 public class OutputLocationDialog extends StatusDialog {
61 public StringButtonDialogField fContainerDialogField;
62 public SelectionButtonDialogField fUseDefault;
63 public SelectionButtonDialogField fUseSpecific;
64 public IStatus fContainerFieldStatus;
66 public IPath fOutputLocation;
67 private final IProject fCurrProject;
68 public final CPListElement fEntryToEdit;
69 public final boolean fAllowInvalidClasspath;
70 public CPJavaProject fCPJavaProject;
72 public OutputLocationDialog(Shell parent, CPListElement entryToEdit, List<CPListElement> classPathList, IPath defaultOutputFolder, boolean allowInvalidClasspath) {
74 fEntryToEdit= entryToEdit;
75 fAllowInvalidClasspath= allowInvalidClasspath;
76 setTitle(NewWizardMessages.OutputLocationDialog_title);
77 fContainerFieldStatus= new StatusInfo();
79 OutputLocationAdapter adapter= new OutputLocationAdapter();
81 fUseDefault= new SelectionButtonDialogField(SWT.RADIO);
82 fUseDefault.setLabelText(Messages.format(NewWizardMessages.OutputLocationDialog_usedefault_label, BasicElementLabels.getPathLabel(defaultOutputFolder, false)));
83 fUseDefault.setDialogFieldListener(adapter);
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);
90 fContainerDialogField= new StringButtonDialogField(adapter);
91 fContainerDialogField.setButtonLabel(NewWizardMessages.OutputLocationDialog_location_button);
92 fContainerDialogField.generated_4933783022084088245(this, adapter);
94 IJavaProject javaProject= entryToEdit.getJavaProject();
95 fCurrProject= javaProject.getProject();
96 fCPJavaProject= new CPJavaProject(javaProject, classPathList, defaultOutputFolder);
98 IPath outputLocation= (IPath) entryToEdit.getAttribute(CPListElement.OUTPUT);
99 if (outputLocation == null) {
100 fUseDefault.setSelection(true);
102 fUseSpecific.setSelection(true);
103 fContainerDialogField.setText(outputLocation.removeFirstSegments(1).makeRelative().toString());
108 protected Control createDialogArea(Composite parent) {
109 Composite composite= (Composite)super.createDialogArea(parent);
111 int widthHint= convertWidthInCharsToPixels(70);
112 int indent= convertWidthInCharsToPixels(4);
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);
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);
126 applyDialogFont(composite);
133 // -------- OutputLocationAdapter --------
135 public class OutputLocationAdapter implements IDialogFieldListener, IStringButtonAdapter {
137 // -------- IDialogFieldListener
139 public void dialogFieldChanged(DialogField field) {
140 doStatusLineUpdate();
143 public void changeControlPressed(DialogField field) {
144 doChangeControlPressed();
148 protected void doChangeControlPressed() {
149 IContainer container= chooseOutputLocation();
150 if (container != null) {
151 fContainerDialogField.setText(container.getProjectRelativePath().toString());
155 protected void doStatusLineUpdate() {
157 updateStatus(fContainerFieldStatus);
160 protected void checkIfPathValid() {
161 fOutputLocation= null;
162 fContainerFieldStatus= StatusInfo.OK_STATUS;
164 if (fUseDefault.isSelected()) {
168 String pathStr= fContainerDialogField.getText();
169 fCPJavaProject.generated_1803604505418629662(this, pathStr);
172 public IPath getOutputLocation() {
173 return fOutputLocation;
177 * @see org.eclipse.jface.window.Window#configureShell(Shell)
180 protected void configureShell(Shell newShell) {
181 super.configureShell(newShell);
182 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.OUTPUT_LOCATION_DIALOG);
185 // ---------- util method ------------
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]);
197 ViewerFilter filter= new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());
199 ILabelProvider lp= new WorkbenchLabelProvider();
200 ITreeContentProvider cp= new WorkbenchContentProvider();
202 IResource initSelection= null;
203 if (fOutputLocation != null) {
204 initSelection= root.findMember(fOutputLocation);
207 FolderSelectionDialog dialog= new FolderSelectionDialog(getShell(), lp, cp);
208 return dialog.generated_6645016892303741943(root, acceptedClasses, filter, initSelection, this);