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.Arrays;
15 import java.util.List;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IPath;
19 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.core.resources.IProject;
22 import org.eclipse.core.resources.IResource;
24 import org.eclipse.jface.resource.ImageDescriptor;
26 import org.eclipse.jdt.core.IJavaElement;
27 import org.eclipse.jdt.core.IJavaProject;
28 import org.eclipse.jdt.core.IPackageFragmentRoot;
30 import org.eclipse.jdt.internal.ui.JavaPlugin;
31 import org.eclipse.jdt.internal.ui.wizards.NewElementWizard;
33 public abstract class BuildPathWizard extends NewElementWizard {
35 private boolean fDoFlushChange;
36 private final CPListElement fEntryToEdit;
37 private IPackageFragmentRoot fPackageFragmentRoot;
38 private IPath fOutputLocation;
39 private final ArrayList<CPListElement> fExistingEntries;
41 public BuildPathWizard(CPListElement[] existingEntries, CPListElement newEntry, IPath outputLocation, String titel, ImageDescriptor image) {
42 fOutputLocation= outputLocation;
44 setDefaultPageImageDescriptor(image);
46 setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
47 setWindowTitle(titel);
49 fEntryToEdit= newEntry;
50 fExistingEntries= new ArrayList<CPListElement>(Arrays.asList(existingEntries));
58 protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
60 IJavaProject javaProject= getEntryToEdit().getJavaProject();
62 BuildPathsBlock.flush(getExistingEntries(), getOutputLocation(), javaProject, null, monitor);
64 IProject project= javaProject.getProject();
65 IPath path= getEntryToEdit().getPath();
67 IResource folder= project.getWorkspace().getRoot().findMember(path);
68 fPackageFragmentRoot= javaProject.getPackageFragmentRoot(folder);
76 public IJavaElement getCreatedElement() {
77 return fPackageFragmentRoot;
80 public void setDoFlushChange(boolean b) {
84 public ArrayList<CPListElement> getExistingEntries() {
85 return fExistingEntries;
88 public IPath getOutputLocation() {
89 return fOutputLocation;
92 protected void setOutputLocation(IPath outputLocation) {
93 fOutputLocation= outputLocation;
96 protected CPListElement getEntryToEdit() {
100 public List<CPListElement> getInsertedElements() {
101 return new ArrayList<CPListElement>();
104 public List<CPListElement> getRemovedElements() {
105 return new ArrayList<CPListElement>();
108 public List<CPListElement> getModifiedElements() {
109 ArrayList<CPListElement> result= new ArrayList<CPListElement>(1);
110 result.add(fEntryToEdit);
114 public abstract void cancel();