KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > exports > PluginExportWizardPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.exports;
12
13 import java.io.File JavaDoc;
14 import java.util.ArrayList JavaDoc;
15
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.core.resources.ResourcesPlugin;
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.jdt.core.IJavaProject;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.pde.core.IModel;
22 import org.eclipse.pde.core.plugin.IPluginModelBase;
23 import org.eclipse.pde.core.plugin.PluginRegistry;
24 import org.eclipse.pde.internal.core.PDECore;
25 import org.eclipse.pde.internal.core.WorkspaceModelManager;
26 import org.eclipse.pde.internal.ui.IHelpContextIds;
27 import org.eclipse.pde.internal.ui.PDEUIMessages;
28 import org.eclipse.pde.internal.ui.util.PersistablePluginObject;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.ui.PlatformUI;
31
32
33 public class PluginExportWizardPage extends BaseExportWizardPage {
34     
35     public PluginExportWizardPage(IStructuredSelection selection) {
36         super(
37             selection,
38             "pluginExport", //$NON-NLS-1$
39
PDEUIMessages.ExportWizard_Plugin_pageBlock);
40         setTitle(PDEUIMessages.ExportWizard_Plugin_pageTitle);
41     }
42     
43     protected Object JavaDoc getInput() {
44         return PDECore.getDefault().getModelManager();
45     }
46
47     public Object JavaDoc[] getListElements() {
48         IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
49         ArrayList JavaDoc result = new ArrayList JavaDoc();
50         for (int i = 0; i < projects.length; i++) {
51             if (!WorkspaceModelManager.isBinaryProject(projects[i])
52                 && WorkspaceModelManager.isPluginProject(projects[i])) {
53                 IModel model = PluginRegistry.findModel(projects[i]);
54                 if (model != null && isValidModel(model) && hasBuildProperties((IPluginModelBase)model)) {
55                     result.add(model);
56                 }
57             }
58         }
59         return result.toArray();
60     }
61     
62     protected void hookHelpContext(Control control) {
63         PlatformUI.getWorkbench().getHelpSystem().setHelp(control, IHelpContextIds.PLUGIN_EXPORT_WIZARD);
64     }
65     
66     private boolean hasBuildProperties(IPluginModelBase model) {
67         File JavaDoc file = new File JavaDoc(model.getInstallLocation(),"build.properties"); //$NON-NLS-1$
68
return file.exists();
69     }
70     
71     /* (non-Javadoc)
72      * @see org.eclipse.pde.internal.ui.wizards.exports.BaseExportWizardPage#isValidModel(org.eclipse.pde.core.IModel)
73      */

74     protected boolean isValidModel(IModel model) {
75         return model != null && model instanceof IPluginModelBase;
76     }
77     
78     /* (non-Javadoc)
79      * @see org.eclipse.pde.internal.ui.wizards.exports.BaseExportWizardPage#findModelFor(org.eclipse.core.runtime.IAdaptable)
80      */

81     protected IModel findModelFor(IAdaptable object) {
82         if (object instanceof IJavaProject)
83             object = ((IJavaProject)object).getProject();
84         if (object instanceof IProject)
85             return PluginRegistry.findModel((IProject)object);
86         if (object instanceof PersistablePluginObject) {
87             IPluginModelBase model = PluginRegistry.findModel(((PersistablePluginObject)object).getPluginID());
88             if (model != null && model.getUnderlyingResource() != null) {
89                 return model;
90             }
91         }
92         return null;
93     }
94     
95     protected boolean isEnableJarButton() {
96         return getSelectedItems().length <= 1;
97     }
98     
99     protected void adjustAdvancedTabsVisibility() {
100         adjustJARSigningTabVisibility();
101         pageChanged();
102     }
103 }
104
Popular Tags