KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > target > NewTargetDefinitionWizard


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.pde.internal.ui.wizards.target;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.pde.internal.ui.PDEPlugin;
18 import org.eclipse.pde.internal.ui.PDEPluginImages;
19 import org.eclipse.pde.internal.ui.PDEUIMessages;
20 import org.eclipse.ui.IWorkbench;
21 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
22
23 public class NewTargetDefinitionWizard extends BasicNewResourceWizard {
24     
25     TargetDefinitionWizardPage fPage;
26     IPath fInitialPath = null;
27     IPath fFilePath = null;
28     
29     public void addPages() {
30         fPage = new TargetDefinitionWizardPage("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(fPage.getFileName());
40         } catch (InvocationTargetException JavaDoc e) {
41             PDEPlugin.logException(e);
42             return false;
43         } catch (InterruptedException JavaDoc e) {
44             return false;
45         }
46         return true;
47     }
48     
49     public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
50         super.init(workbench, currentSelection);
51         setWindowTitle(PDEUIMessages.NewTargetProfileWizard_title);
52         setNeedsProgressMonitor(true);
53     }
54     
55     protected void initializeDefaultPageImageDescriptor() {
56         setDefaultPageImageDescriptor(PDEPluginImages.DESC_TARGET_WIZ);
57     }
58     
59     private BaseTargetDefinitionOperation getOperation() {
60         int option = fPage.getInitializationOption();
61         if (option == TargetDefinitionWizardPage.USE_DEFAULT)
62             return new BaseTargetDefinitionOperation(fPage.createNewFile());
63         else if (option == TargetDefinitionWizardPage.USE_CURRENT_TP)
64             return new TargetDefinitionFromPlatformOperation(fPage.createNewFile());
65         return new TargetDefinitionFromTargetOperation(fPage.createNewFile(), fPage.getTargetId());
66     }
67     
68     public void setInitialPath(IPath path) {
69         fInitialPath = path;
70     }
71     
72     public IPath getFilePath() {
73         return fFilePath;
74     }
75
76 }
77
Popular Tags