01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.target;
11:
12: import java.lang.reflect.InvocationTargetException;
13:
14: import org.eclipse.core.runtime.IPath;
15: import org.eclipse.jface.viewers.IStructuredSelection;
16: import org.eclipse.pde.internal.ui.PDEPlugin;
17: import org.eclipse.pde.internal.ui.PDEPluginImages;
18: import org.eclipse.pde.internal.ui.PDEUIMessages;
19: import org.eclipse.ui.IWorkbench;
20: import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
21:
22: public class NewTargetDefinitionWizard extends BasicNewResourceWizard {
23:
24: TargetDefinitionWizardPage fPage;
25: IPath fInitialPath = null;
26: IPath fFilePath = null;
27:
28: public void addPages() {
29: fPage = new TargetDefinitionWizardPage(
30: "profile", getSelection()); //$NON-NLS-1$
31: if (fInitialPath != null)
32: fPage.setContainerFullPath(fInitialPath);
33: addPage(fPage);
34: }
35:
36: public boolean performFinish() {
37: try {
38: getContainer().run(false, true, getOperation());
39: fFilePath = fPage.getContainerFullPath().append(
40: fPage.getFileName());
41: } catch (InvocationTargetException e) {
42: PDEPlugin.logException(e);
43: return false;
44: } catch (InterruptedException e) {
45: return false;
46: }
47: return true;
48: }
49:
50: public void init(IWorkbench workbench,
51: IStructuredSelection currentSelection) {
52: super .init(workbench, currentSelection);
53: setWindowTitle(PDEUIMessages.NewTargetProfileWizard_title);
54: setNeedsProgressMonitor(true);
55: }
56:
57: protected void initializeDefaultPageImageDescriptor() {
58: setDefaultPageImageDescriptor(PDEPluginImages.DESC_TARGET_WIZ);
59: }
60:
61: private BaseTargetDefinitionOperation getOperation() {
62: int option = fPage.getInitializationOption();
63: if (option == TargetDefinitionWizardPage.USE_DEFAULT)
64: return new BaseTargetDefinitionOperation(fPage
65: .createNewFile());
66: else if (option == TargetDefinitionWizardPage.USE_CURRENT_TP)
67: return new TargetDefinitionFromPlatformOperation(fPage
68: .createNewFile());
69: return new TargetDefinitionFromTargetOperation(fPage
70: .createNewFile(), fPage.getTargetId());
71: }
72:
73: public void setInitialPath(IPath path) {
74: fInitialPath = path;
75: }
76:
77: public IPath getFilePath() {
78: return fFilePath;
79: }
80:
81: }
|