001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.exports;
011:
012: import java.io.File;
013: import java.util.ArrayList;
014:
015: import org.eclipse.core.resources.IProject;
016: import org.eclipse.core.resources.ResourcesPlugin;
017: import org.eclipse.core.runtime.IAdaptable;
018: import org.eclipse.jdt.core.IJavaProject;
019: import org.eclipse.jface.viewers.IStructuredSelection;
020: import org.eclipse.pde.core.IModel;
021: import org.eclipse.pde.core.plugin.IPluginModelBase;
022: import org.eclipse.pde.core.plugin.PluginRegistry;
023: import org.eclipse.pde.internal.core.PDECore;
024: import org.eclipse.pde.internal.core.WorkspaceModelManager;
025: import org.eclipse.pde.internal.ui.IHelpContextIds;
026: import org.eclipse.pde.internal.ui.PDEUIMessages;
027: import org.eclipse.pde.internal.ui.util.PersistablePluginObject;
028: import org.eclipse.swt.widgets.Control;
029: import org.eclipse.ui.PlatformUI;
030:
031: public class PluginExportWizardPage extends BaseExportWizardPage {
032:
033: public PluginExportWizardPage(IStructuredSelection selection) {
034: super (selection, "pluginExport", //$NON-NLS-1$
035: PDEUIMessages.ExportWizard_Plugin_pageBlock);
036: setTitle(PDEUIMessages.ExportWizard_Plugin_pageTitle);
037: }
038:
039: protected Object getInput() {
040: return PDECore.getDefault().getModelManager();
041: }
042:
043: public Object[] getListElements() {
044: IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
045: .getProjects();
046: ArrayList result = new ArrayList();
047: for (int i = 0; i < projects.length; i++) {
048: if (!WorkspaceModelManager.isBinaryProject(projects[i])
049: && WorkspaceModelManager
050: .isPluginProject(projects[i])) {
051: IModel model = PluginRegistry.findModel(projects[i]);
052: if (model != null && isValidModel(model)
053: && hasBuildProperties((IPluginModelBase) model)) {
054: result.add(model);
055: }
056: }
057: }
058: return result.toArray();
059: }
060:
061: protected void hookHelpContext(Control control) {
062: PlatformUI.getWorkbench().getHelpSystem().setHelp(control,
063: IHelpContextIds.PLUGIN_EXPORT_WIZARD);
064: }
065:
066: private boolean hasBuildProperties(IPluginModelBase model) {
067: File file = new File(model.getInstallLocation(),
068: "build.properties"); //$NON-NLS-1$
069: return file.exists();
070: }
071:
072: /* (non-Javadoc)
073: * @see org.eclipse.pde.internal.ui.wizards.exports.BaseExportWizardPage#isValidModel(org.eclipse.pde.core.IModel)
074: */
075: protected boolean isValidModel(IModel model) {
076: return model != null && model instanceof IPluginModelBase;
077: }
078:
079: /* (non-Javadoc)
080: * @see org.eclipse.pde.internal.ui.wizards.exports.BaseExportWizardPage#findModelFor(org.eclipse.core.runtime.IAdaptable)
081: */
082: protected IModel findModelFor(IAdaptable object) {
083: if (object instanceof IJavaProject)
084: object = ((IJavaProject) object).getProject();
085: if (object instanceof IProject)
086: return PluginRegistry.findModel((IProject) object);
087: if (object instanceof PersistablePluginObject) {
088: IPluginModelBase model = PluginRegistry
089: .findModel(((PersistablePluginObject) object)
090: .getPluginID());
091: if (model != null && model.getUnderlyingResource() != null) {
092: return model;
093: }
094: }
095: return null;
096: }
097:
098: protected boolean isEnableJarButton() {
099: return getSelectedItems().length <= 1;
100: }
101:
102: protected void adjustAdvancedTabsVisibility() {
103: adjustJARSigningTabVisibility();
104: pageChanged();
105: }
106: }
|