Author: rob.stryker(a)jboss.com
Date: 2009-10-08 18:23:02 -0400 (Thu, 08 Oct 2009)
New Revision: 17990
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportDataModelProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportPage.java
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportWizard.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/META-INF/MANIFEST.MF
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/util/VCFUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/vcf/ModuleExportOperation.java
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/plugin.xml
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/Messages.java
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/WTPOveridePlugin.java
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/messages.properties
Log:
JBIDE-5005 - Export wizard (etc). the majority of the work. Only tiny changes will still
be required
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/META-INF/MANIFEST.MF 2009-10-08
21:03:40 UTC (rev 17989)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/META-INF/MANIFEST.MF 2009-10-08
22:23:02 UTC (rev 17990)
@@ -20,7 +20,8 @@
org.eclipse.jst.common.frameworks;bundle-version="1.1.300",
org.eclipse.core.commands;bundle-version="3.5.0",
org.eclipse.jst.server.core;bundle-version="1.2.0",
- org.eclipse.jdt.core;bundle-version="3.5.0"
+ org.eclipse.jdt.core;bundle-version="3.5.0",
+ org.eclipse.wst.common.emfworkbench.integration;bundle-version="1.1.301"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.jboss.ide.eclipse.as.wtp.core.modules,
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/util/VCFUtil.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/util/VCFUtil.java 2009-10-08
21:03:40 UTC (rev 17989)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/util/VCFUtil.java 2009-10-08
22:23:02 UTC (rev 17990)
@@ -12,19 +12,29 @@
import java.util.Arrays;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.common.componentcore.ModuleCoreNature;
import
org.eclipse.wst.common.componentcore.datamodel.properties.ICreateReferenceComponentsDataModelProperties;
import
org.eclipse.wst.common.componentcore.internal.operation.CreateReferenceComponentsDataModelProvider;
+import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
+import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
+import org.eclipse.wst.common.project.facet.core.IGroup;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.jboss.ide.eclipse.as.wtp.core.ASWTPToolsPlugin;
public class VCFUtil {
@@ -59,4 +69,49 @@
throw new CoreException(status);
}
}
+
+ /**
+ * Finds the one facet which is in the "modules" group
+ * @param project
+ * @return
+ */
+ public static IProjectFacet getModuleFacet(IProject proj) {
+ if( ModuleCoreNature.isFlexibleProject(proj)) {
+ try {
+ IGroup group = ProjectFacetsManager.getGroup("modules");
+ if( group != null ) {
+ Set<IProjectFacetVersion> set = group.getMembers();
+ Iterator<IProjectFacetVersion> i = set.iterator();
+ while(i.hasNext()) {
+ IProjectFacet facet = i.next().getProjectFacet();
+ if( FacetedProjectFramework.hasProjectFacet(proj, facet.getId())) {
+ return facet;
+ }
+ }
+ }
+ } catch( CoreException ce ) {
+ }
+ }
+ return null;
+ }
+
+ // TODO can increase efficiency by using a pre-loaded map
+ public static String getModuleFacetExtension(IProject project) {
+ IProjectFacet facet = getModuleFacet(project);
+ if( facet != null ) {
+ if( facet.getId().equals(IModuleConstants.JST_WEB_MODULE)) return ".war";
+ if( facet.getId().equals(IModuleConstants.JST_EJB_MODULE)) return ".jar";
+ if( facet.getId().equals(IModuleConstants.JST_UTILITY_MODULE)) return
".jar";
+ if( facet.getId().equals(IModuleConstants.JST_EAR_MODULE)) return ".ear";
+ if( facet.getId().equals(IModuleConstants.WST_WEB_MODULE)) return ".war";
+ if( facet.getId().equals(IModuleConstants.JST_APPCLIENT_MODULE)) return
".jar";
+ if( facet.getId().equals(IModuleConstants.JST_CONNECTOR_MODULE)) return
".rar";
+ if( facet.getId().equals("jst.jboss.esb")) return ".esb";
+ if( facet.getId().equals("jbt.bpel.facet.core")) return ".bpel";
+ // TODO add our extensions
+ }
+ return null;
+ }
+
+
}
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/vcf/ModuleExportOperation.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/vcf/ModuleExportOperation.java 2009-10-08
21:03:40 UTC (rev 17989)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.core/src/org/jboss/ide/eclipse/as/wtp/core/vcf/ModuleExportOperation.java 2009-10-08
22:23:02 UTC (rev 17990)
@@ -12,9 +12,6 @@
import static
org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.ARCHIVE_DESTINATION;
import static
org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.COMPONENT;
-import static
org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.EXPORT_SOURCE_FILES;
-import static
org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.OPTIMIZE_FOR_SPECIFIC_RUNTIME;
-import static
org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.RUNTIME_SPECIFIC_PARTICIPANTS;
import static
org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.RUN_BUILD;
import java.io.File;
@@ -24,7 +21,6 @@
import java.lang.reflect.InvocationTargetException;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@@ -50,7 +46,6 @@
import org.eclipse.core.runtime.jobs.MultiRule;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException;
-import
org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties.IArchiveExportParticipantData;
import org.eclipse.jst.j2ee.internal.archive.operations.EJBArchiveOpsResourceHandler;
import org.eclipse.jst.j2ee.internal.plugin.LibCopyBuilder;
import org.eclipse.jst.j2ee.internal.project.ProjectSupportResourceHandler;
@@ -62,21 +57,22 @@
import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
-import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IModuleType;
import org.eclipse.wst.server.core.ServerUtil;
import org.eclipse.wst.server.core.model.IModuleFile;
import org.eclipse.wst.server.core.model.IModuleFolder;
import org.eclipse.wst.server.core.model.IModuleResource;
import org.eclipse.wst.server.core.model.ModuleDelegate;
+import org.eclipse.wst.server.core.util.ProjectModule;
+import org.jboss.ide.eclipse.as.wtp.core.modules.IJBTModule;
-public abstract class ModuleExportOperation extends AbstractDataModelOperation {
+public class ModuleExportOperation extends AbstractDataModelOperation {
protected IProgressMonitor progressMonitor;
private IVirtualComponent component;
private IModule module;
private IPath destinationPath;
- private boolean exportSource = false;
public ModuleExportOperation() {
super();
@@ -91,7 +87,6 @@
protected final int LIB_BUILDER_WORK = 100;
protected final int EXPORT_WORK = 1000;
protected final int CLOSE_WORK = 10;
- protected final int SINGLE_PARTICIPANT_WORK = 200;
protected int computeTotalWork() {
int totalWork = REFRESH_WORK;
@@ -99,65 +94,36 @@
totalWork += JAVA_BUILDER_WORK + LIB_BUILDER_WORK;
}
totalWork += EXPORT_WORK + CLOSE_WORK;
-
- final IDataModel dm = getDataModel();
-
- if( dm.getProperty( OPTIMIZE_FOR_SPECIFIC_RUNTIME ) == Boolean.TRUE ) {
- final List<IArchiveExportParticipantData> extensions
- = (List<IArchiveExportParticipantData>) dm.getProperty(
RUNTIME_SPECIFIC_PARTICIPANTS );
- totalWork += extensions.size() * SINGLE_PARTICIPANT_WORK;
- }
-
return totalWork;
}
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws
ExecutionException {
setComponent((IVirtualComponent) model.getProperty(COMPONENT));
setDestinationPath(new Path(model.getStringProperty(ARCHIVE_DESTINATION)));
-// setExportSource(model.getBooleanProperty(EXPORT_SOURCE_FILES));
- try
- {
+ try {
monitor.beginTask(ProjectSupportResourceHandler.getString(ProjectSupportResourceHandler.Exporting_archive,
new Object [] { getDestinationPath().lastSegment() }), computeTotalWork());
setProgressMonitor(monitor);
-
- try {
- // defect 240999
- component.getProject().refreshLocal(IResource.DEPTH_INFINITE, new
SubProgressMonitor(monitor, REFRESH_WORK));
- if (model.getBooleanProperty(RUN_BUILD)) {
- runNecessaryBuilders(component, new SubProgressMonitor(monitor, JAVA_BUILDER_WORK
+ LIB_BUILDER_WORK));
- }
- export();
- } catch (Exception e) {
- monitor.worked(CLOSE_WORK);
- throw new ExecutionException(EJBArchiveOpsResourceHandler.Error_exporting__UI_ +
archiveString(), e);
- }
-
- final IDataModel dm = getDataModel();
-
- if( dm.getProperty( OPTIMIZE_FOR_SPECIFIC_RUNTIME ) == Boolean.TRUE )
- {
- for( IArchiveExportParticipantData extData
- : (List<IArchiveExportParticipantData>) dm.getProperty(
RUNTIME_SPECIFIC_PARTICIPANTS ) )
- {
- final IDataModelOperation op
- = extData.getParticipant().createOperation(
extData.getDataModel() );
-
- op.execute( null, null );
- monitor.worked( SINGLE_PARTICIPANT_WORK );
- }
+ if( component != null ) {
+ try {
+ // defect 240999
+ component.getProject().refreshLocal(IResource.DEPTH_INFINITE, new
SubProgressMonitor(monitor, REFRESH_WORK));
+ if (model.getBooleanProperty(RUN_BUILD)) {
+ runNecessaryBuilders(component, new SubProgressMonitor(monitor,
JAVA_BUILDER_WORK + LIB_BUILDER_WORK));
+ }
+ export();
+ } catch (Exception e) {
+ monitor.worked(CLOSE_WORK);
+ throw new ExecutionException(EJBArchiveOpsResourceHandler.Error_exporting__UI_ +
component.getProject().getName(), e);
+ }
}
- }
- finally
- {
+ } finally {
monitor.done();
}
return OK_STATUS;
}
- protected abstract String archiveString();
-
protected void setProgressMonitor(IProgressMonitor newProgressMonitor) {
progressMonitor = newProgressMonitor;
}
@@ -184,21 +150,19 @@
protected void setDestinationPath(IPath newDestinationPath) {
destinationPath = newDestinationPath;
}
-
-// protected boolean isExportSource() {
-// return exportSource;
-// }
-//
-// protected void setExportSource(boolean newExportSource) {
-// exportSource = newExportSource;
-// }
-
+
+ /*
+ * It's assumed that if the module is a "Project Module" then there's
only
+ * one of these per project. This might not be a great assumption, but
+ * accepting the first ProjectModule which responds is how the behaviour works here.
+ */
protected void setModule() {
- String moduleType = getModuleTypeID();
- if( component != null && component.getProject() != null && moduleType
!= null) {
+ if( component != null && component.getProject() != null) {
IModule[] modules = ServerUtil.getModules(component.getProject());
+ ModuleDelegate delegate;
for( int i = 0; i < modules.length; i++ ) {
- if( modules[i].getModuleType().getId().equals(moduleType)) {
+ delegate = (ModuleDelegate)modules[i].loadAdapter(ModuleDelegate.class, new
NullProgressMonitor());
+ if( delegate != null && delegate instanceof ProjectModule ) {
module = modules[i];
return;
}
@@ -207,15 +171,15 @@
module = null;
}
- protected abstract String getModuleTypeID();
-
-
/* Return null to skip this child */
protected /* abstract */ String getChildURI(IModule parent, IModule child) {
IEnterpriseApplication app =
(IEnterpriseApplication)parent.loadAdapter(IEnterpriseApplication.class, new
NullProgressMonitor());
if( app != null ) {
return app.getURI(child);
}
+ IJBTModule mod = (IJBTModule)parent.loadAdapter(IJBTModule.class, new
NullProgressMonitor());
+ if( mod != null )
+ return mod.getURI(child);
return null;
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/plugin.xml 2009-10-08 21:03:40 UTC
(rev 17989)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/plugin.xml 2009-10-08 22:23:02 UTC
(rev 17990)
@@ -68,4 +68,23 @@
name="Build Path Class Folders">
</referenceFragment>
</extension>
+
+
+
+ <extension
+ point="org.eclipse.ui.exportWizards">
+ <wizard
+ category="org.eclipse.jst.j2ee.internal"
+
class="org.jboss.ide.eclipse.as.wtp.ui.wizards.export.ProjectModuleExportWizard"
+ icon="icons/jar_obj.gif"
+
id="org.jboss.ide.eclipse.as.wtp.ui.wizards.export.ProjectModuleExportWizard"
+ name="Module Archive">
+ <description>
+ Export this project as an arbitrary zipped archive file.
+ </description>
+ <selection
+ class="org.eclipse.core.resources.IResource">
+ </selection>
+ </wizard>
+ </extension>
</plugin>
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/Messages.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/Messages.java 2009-10-08
21:03:40 UTC (rev 17989)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/Messages.java 2009-10-08
22:23:02 UTC (rev 17990)
@@ -11,6 +11,19 @@
public static String AddModuleDependenciesPropertiesPage_SourceColumn;
public static String J2EEDependenciesPage_Description;
public static String J2EEDependenciesPage_ErrorCheckingFacets;
+ public static String MODULE_EXISTS_ERROR;
+ public static String DESTINATION_INVALID;
+ public static String DESTINATION_ARCHIVE_SHOULD_END_WITH;
+ public static String RESOURCE_EXISTS_ERROR;
+ public static String IS_READ_ONLY;
+ public static String Export_LabelDestination;
+ public static String Export_WizardTitle;
+ public static String Export_PageTitle;
+ public static String Export_PageDescription;
+ public static String Export_LabelProject;
+ public static String Export_LabelBrowse;
+ public static String Export_OverwriteCheckbox;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/WTPOveridePlugin.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/WTPOveridePlugin.java 2009-10-08
21:03:40 UTC (rev 17989)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/WTPOveridePlugin.java 2009-10-08
22:23:02 UTC (rev 17990)
@@ -64,6 +64,18 @@
return new Status(severity, PLUGIN_ID, aCode,
aMessage != null ? aMessage : "No message.", exception); //$NON-NLS-1$
}
+ public static IStatus createErrorStatus(String message) {
+ return createErrorStatus(message, null);
+ }
+ public static IStatus createWarningStatus(String message) {
+ return createWarningStatus(message, null);
+ }
+ public static IStatus createErrorStatus(String message, Throwable exception) {
+ return new Status(IStatus.ERROR, PLUGIN_ID, -1, message, exception);
+ }
+ public static IStatus createWarningStatus(String message, Throwable exception) {
+ return new Status(IStatus.WARNING, PLUGIN_ID, -1, message, exception);
+ }
public static IStatus createErrorStatus(int aCode, String aMessage,
Throwable exception) {
return createStatus(IStatus.ERROR, aCode, aMessage, exception);
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/messages.properties
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/messages.properties 2009-10-08
21:03:40 UTC (rev 17989)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/messages.properties 2009-10-08
22:23:02 UTC (rev 17990)
@@ -5,3 +5,15 @@
AddModuleDependenciesPropertiesPage_SourceColumn=Source
J2EEDependenciesPage_Description=ModuleDependency Page Description
J2EEDependenciesPage_ErrorCheckingFacets=Error Checking Project Facets
+Export_WizardTitle=Export a Project Module
+Export_PageTitle=Export a Project Module
+Export_PageDescription=Export a project according to it's "module"
structure.
+Export_LabelDestination=Destination
+Export_LabelProject=Project
+Export_LabelBrowse=Browse...
+Export_OverwriteCheckbox=Overwrite existing file
+MODULE_EXISTS_ERROR=Module name is invalid.
+DESTINATION_INVALID=Destination archive is invalid.
+DESTINATION_ARCHIVE_SHOULD_END_WITH=Destination archive should end with {0}.
+RESOURCE_EXISTS_ERROR=Resource {0} already exists. If you wish to overwrite select the
"Overwrite Existing file" option.
+IS_READ_ONLY=Destination location is read only.
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportDataModelProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportDataModelProvider.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportDataModelProvider.java 2009-10-08
22:23:02 UTC (rev 17990)
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.wtp.ui.wizards.export;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import
org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
+import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonMessages;
+import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.jboss.ide.eclipse.as.wtp.core.util.VCFUtil;
+import org.jboss.ide.eclipse.as.wtp.core.vcf.ModuleExportOperation;
+import org.jboss.ide.eclipse.as.wtp.ui.Messages;
+import org.jboss.ide.eclipse.as.wtp.ui.WTPOveridePlugin;
+
+public class ProjectModuleExportDataModelProvider extends
+ AbstractDataModelProvider implements IJ2EEComponentExportDataModelProperties {
+
+ public IDataModelOperation getDefaultOperation() {
+ return new ModuleExportOperation(model);
+ }
+ public HashMap<String, IVirtualComponent> componentMap;
+
+ public ProjectModuleExportDataModelProvider() {
+ super();
+ }
+
+ public Set getPropertyNames() {
+ Set<String> propertyNames = super.getPropertyNames();
+ propertyNames.add(PROJECT_NAME);
+ propertyNames.add(ARCHIVE_DESTINATION);
+ propertyNames.add(OVERWRITE_EXISTING);
+ propertyNames.add(RUN_BUILD);
+ propertyNames.add(COMPONENT);
+ return propertyNames;
+ }
+
+ public Object getDefaultProperty(String propertyName) {
+ if (propertyName.equals(ARCHIVE_DESTINATION)) {
+ return ""; //$NON-NLS-1$
+ } else if (propertyName.equals(OVERWRITE_EXISTING)) {
+ return Boolean.FALSE;
+ } else if( propertyName.equals(RUN_BUILD))
+ return Boolean.TRUE;
+ return super.getDefaultProperty(propertyName);
+ }
+
+ public boolean isPropertyEnabled( final String propertyName ) {
+ return true;
+ }
+
+ public boolean propertySet(String propertyName, Object propertyValue) {
+ boolean set = super.propertySet(propertyName, propertyValue);
+ final IDataModel dm = getDataModel();
+
+ if (propertyName.equals(PROJECT_NAME)) {
+ if (getComponentMap().isEmpty())
+ intializeComponentMap();
+ IVirtualComponent component = (IVirtualComponent)
getComponentMap().get(propertyValue);
+ if (null != component && component.getName().equals(propertyValue)) {
+ setProperty(COMPONENT, component);
+ } else {
+ setProperty(COMPONENT, null);
+ }
+
+ dm.notifyPropertyChange( RUNTIME, IDataModel.VALID_VALUES_CHG );
+ IFacetedProject fproj = null;
+ if( component != null ) {
+ try {
+ fproj = ProjectFacetsManager.create( component.getProject() );
+ } catch( CoreException e ) {
+ WTPOveridePlugin.logError(e );
+ }
+ }
+ }
+ return set;
+ }
+
+ public HashMap<String, IVirtualComponent> getComponentMap() {
+ if (componentMap == null)
+ componentMap = new HashMap<String, IVirtualComponent>();
+ return componentMap;
+ }
+
+ public void intializeComponentMap() {
+ IVirtualComponent[] comps = ComponentUtilities.getAllWorkbenchComponents();
+ for (int i = 0; i < comps.length; i++) {
+ getComponentMap().put(comps[i].getName(), comps[i]);
+ }
+ }
+
+ /**
+ * Populate the resource name combo with projects that are not encrypted.
+ */
+ public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) {
+ if (propertyName.equals(PROJECT_NAME)) {
+ List<String> componentNames = new ArrayList<String>();
+ IVirtualComponent[] wbComps = ComponentUtilities.getAllWorkbenchComponents();
+ List<IVirtualComponent> relevantComponents = new
ArrayList<IVirtualComponent>();
+ for (int i = 0; i < wbComps.length; i++) {
+ relevantComponents.add(wbComps[i]);
+ getComponentMap().put(wbComps[i].getName(), wbComps[i]);
+ }
+
+ if (relevantComponents == null || relevantComponents.size() == 0)
+ return null;
+
+ for (int j = 0; j < relevantComponents.size(); j++) {
+ componentNames.add(((IVirtualComponent) relevantComponents.get(j)).getName());
+ }
+ String[] names = (String[]) componentNames.toArray(new
String[componentNames.size()]);
+
+ return DataModelPropertyDescriptor.createDescriptors(names);
+ }
+
+ return super.getValidPropertyDescriptors(propertyName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#doValidateProperty(java.lang.String)
+ */
+ public IStatus validate(String propertyName) {
+ if (PROJECT_NAME.equals(propertyName)) {
+ String projectName = (String) model.getProperty(PROJECT_NAME);
+ if (projectName == null || projectName.equals("")) //$NON-NLS-1$
+ return WTPOveridePlugin.createErrorStatus(Messages.MODULE_EXISTS_ERROR);
+ IVirtualComponent component = (IVirtualComponent) componentMap.get(projectName);
+ if (component == null) {
+ return WTPOveridePlugin.createErrorStatus(Messages.MODULE_EXISTS_ERROR);
+ }
+ }
+ if (ARCHIVE_DESTINATION.equals(propertyName)) {
+ String archiveLocation = (String) model.getProperty(ARCHIVE_DESTINATION);
+ if (!model.isPropertySet(ARCHIVE_DESTINATION) || archiveLocation.equals(""))
{ //$NON-NLS-1$
+ return WTPOveridePlugin.createErrorStatus(Messages.DESTINATION_INVALID);
+ } else if (model.isPropertySet(ARCHIVE_DESTINATION)) {
+ IStatus tempStatus = validateLocation(archiveLocation);
+ if (tempStatus != OK_STATUS)
+ return tempStatus;
+ } else if (model.isPropertySet(ARCHIVE_DESTINATION) &&
!validateModuleType(archiveLocation)) {
+ String assumedExtension = VCFUtil.getModuleFacetExtension(getProject());
+ if( assumedExtension != null )
+ return
WTPOveridePlugin.createWarningStatus(NLS.bind(Messages.DESTINATION_ARCHIVE_SHOULD_END_WITH,
assumedExtension));
+ }
+ }
+ if (ARCHIVE_DESTINATION.equals(propertyName) ||
OVERWRITE_EXISTING.equals(propertyName)) {
+ String location = (String) getProperty(ARCHIVE_DESTINATION);
+ if (checkForExistingFileResource(location)) {
+ return WTPOveridePlugin.createErrorStatus(NLS.bind(Messages.RESOURCE_EXISTS_ERROR,
location));
+ }
+ }
+ return OK_STATUS;
+ }
+
+ private IStatus validateLocation(String archiveLocation) {
+ IPath path = null;
+ try {
+ path = new Path(archiveLocation);
+ } catch (IllegalArgumentException ex) {
+ return WTPOveridePlugin.createErrorStatus(Messages.DESTINATION_INVALID);
+ }
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IStatus status = workspace.validateName(path.lastSegment(), IResource.FILE);
+ if (!status.isOK()) {
+ return status;
+ }
+ String device = path.getDevice();
+ if (device == null)
+ return OK_STATUS;
+ if (path == null || device.length() == 1 && device.charAt(0) ==
IPath.DEVICE_SEPARATOR)
+ return WTPOveridePlugin.createErrorStatus(Messages.DESTINATION_INVALID);
+
+ if (!path.toFile().canWrite()) {
+ if (path.toFile().exists()) {
+ return WTPOveridePlugin.createErrorStatus(Messages.IS_READ_ONLY);
+ }
+ boolean OK = false;
+ path = path.removeLastSegments(1);
+ for (int i = 1; !OK && i < 20 && path.segmentCount() > 0; i++)
{
+ if (path.toFile().exists()) {
+ OK = true;
+ }
+ status = workspace.validateName(path.lastSegment(), IResource.FOLDER);
+ if (!status.isOK()) {
+ return WTPOveridePlugin.createErrorStatus(Messages.DESTINATION_INVALID);
+ }
+ path = path.removeLastSegments(1);
+ }
+ }
+
+ return OK_STATUS;
+ }
+
+ private boolean checkForExistingFileResource(String fileName) {
+ if (!model.getBooleanProperty(OVERWRITE_EXISTING)) {
+ java.io.File externalFile = new java.io.File(fileName);
+ if (externalFile != null && externalFile.exists())
+ return true;
+ }
+ return false;
+ }
+
+ private boolean validateModuleType(String archive) {
+ String assumedExtension = VCFUtil.getModuleFacetExtension(getProject());
+ if( archive.length() < 4)
+ return false;
+ String lastFour = archive.substring(archive.length() - 4, archive.length());
+ if (!lastFour.equalsIgnoreCase(assumedExtension)) {
+ return false;
+ }
+ return true;
+ }
+
+ private IProject getProject() {
+ final IVirtualComponent component = (IVirtualComponent) getProperty( COMPONENT );
+ return component == null ? null : component.getProject();
+ }
+
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportPage.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportPage.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportPage.java 2009-10-08
22:23:02 UTC (rev 17990)
@@ -0,0 +1,205 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.wtp.ui.wizards.export;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import
org.eclipse.jst.j2ee.datamodel.properties.IJ2EEComponentExportDataModelProperties;
+import org.eclipse.jst.j2ee.internal.plugin.J2EEUIMessages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.wst.common.componentcore.ModuleCoreNature;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage;
+import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
+import org.eclipse.wst.common.project.facet.core.IGroup;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.jboss.ide.eclipse.as.wtp.core.util.VCFUtil;
+import org.jboss.ide.eclipse.as.wtp.ui.Messages;
+
+public class ProjectModuleExportPage extends DataModelWizardPage {
+ private static boolean isWindows =
SWT.getPlatform().toLowerCase().startsWith("win"); //$NON-NLS-1$
+ private static final int SIZING_TEXT_FIELD_WIDTH = 305;
+ protected static final String STORE_PREFIX = "JBT_EXPORT_"; //$NON-NLS-1$
+ protected static final String STORE_OVERWRITE = "OVERWRITE"; //$NON-NLS-1$
+
+ protected IStructuredSelection selection;
+ private Combo resourceNameCombo;
+ private Combo destinationNameCombo;
+ private Button destinationBrowseButton;
+ protected Button overwriteExistingFilesCheckbox;
+
+ public ProjectModuleExportPage(IDataModel model, String pageName, IStructuredSelection
selection) {
+ super(model, pageName);
+ setTitle(Messages.Export_PageTitle);
+ setDescription(Messages.Export_PageDescription);
+ //setImageDescriptor(ESBSharedImages.getImageDescriptor(ESBSharedImages.WIZARD_NEW_PROJECT));
+ this.selection = selection;
+ if( selection != null && selection.getFirstElement() != null ) {
+ Object o = selection.getFirstElement();
+ if( o instanceof IProject ) {
+ model.setProperty(IJ2EEComponentExportDataModelProperties.PROJECT_NAME,
((IProject)o).getName());
+ }
+ }
+ }
+
+ @Override
+ protected String[] getValidationPropertyNames() {
+ return new String[]{IJ2EEComponentExportDataModelProperties.PROJECT_NAME,
+ IJ2EEComponentExportDataModelProperties.ARCHIVE_DESTINATION,
+ IJ2EEComponentExportDataModelProperties.OVERWRITE_EXISTING};
+ }
+
+ @Override
+ protected Composite createTopLevelComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout(1, false);
+ composite.setLayout(layout);
+
+ createSourceAndDestinationGroup(composite);
+ createOptionsGroup(composite);
+
+ setupInfopop(composite);
+ restoreWidgetValues();
+ Dialog.applyDialogFont(parent);
+ return composite;
+ }
+
+ private void createSourceAndDestinationGroup(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout(3, false);
+ composite.setLayout(layout);
+ createExportComponentGroup(composite);
+ createDestinationGroup(composite);
+ }
+
+ protected void createExportComponentGroup(Composite parent) {
+ //Project label
+ Label projectLabel = new Label(parent, SWT.NONE);
+ projectLabel.setText(Messages.Export_LabelProject);
+ //Project combo
+ resourceNameCombo = new Combo(parent, SWT.SINGLE | SWT.BORDER);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.widthHint = SIZING_TEXT_FIELD_WIDTH;
+ resourceNameCombo.setLayoutData(data);
+ synchHelper.synchCombo(resourceNameCombo,
IJ2EEComponentExportDataModelProperties.PROJECT_NAME, null);
+ new Label(parent, SWT.NONE);//Pad label
+ }
+
+ protected void createDestinationGroup(org.eclipse.swt.widgets.Composite parent) {
+
+ //Destination label
+ Label destinationLabel = new Label(parent, SWT.NONE);
+ destinationLabel.setText(Messages.Export_LabelDestination);
+ // destination name combo field
+ destinationNameCombo = new Combo(parent, SWT.SINGLE | SWT.BORDER);
+ destinationNameCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ synchHelper.synchCombo(destinationNameCombo,
IJ2EEComponentExportDataModelProperties.ARCHIVE_DESTINATION, null);
+
+ // destination browse button
+ destinationBrowseButton = new Button(parent, SWT.PUSH);
+ destinationBrowseButton.setText(Messages.Export_LabelBrowse);
+ destinationBrowseButton.setLayoutData((new GridData(GridData.FILL_HORIZONTAL)));
+ destinationBrowseButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ handleDestinationBrowseButtonPressed();
+ }
+ });
+ destinationBrowseButton.setEnabled(true);
+ }
+
+ protected void handleDestinationBrowseButtonPressed() {
+
+ FileDialog dialog = new FileDialog(destinationNameCombo.getShell(), SWT.SAVE);
+ String fileName =
getDataModel().getStringProperty(IJ2EEComponentExportDataModelProperties.PROJECT_NAME);
+ String[] filters = getFilterExpression();
+ if (filters.length != 0 && filters[0] != null &&
filters[0].indexOf('.') != -1) {
+ fileName += filters[0].substring(filters[0].indexOf('.'));
+ }
+ dialog.setFileName(fileName);
+ if (isWindows) {
+ dialog.setFilterExtensions(filters);
+ }
+ String filename = dialog.open();
+ if (filename != null)
+ destinationNameCombo.setText(filename);
+ }
+
+ /**
+ * Return the most likely suffix for this archive
+ * @return
+ */
+ protected String[] getFilterExpression() {
+ return new String[0];
+ }
+
+ protected void restoreWidgetValues() {
+ IDialogSettings settings = getDialogSettings();
+ if (settings != null) {
+ String[] sourceNames = settings.getArray(STORE_PREFIX + getModuleFacet());
+ if (sourceNames == null)
+ return; // ie.- no settings stored
+ for (int i = 0; i < sourceNames.length; i++) {
+ if (sourceNames[i] == null)
+ sourceNames[i] = ""; //$NON-NLS-1$
+ }
+ destinationNameCombo.setItems(sourceNames);
+ boolean overwrite = settings.getBoolean(STORE_PREFIX + STORE_OVERWRITE);
+ model.setBooleanProperty(IJ2EEComponentExportDataModelProperties.OVERWRITE_EXISTING,
overwrite);
+ }
+ }
+
+ protected void createOptionsGroup(Composite parent) {
+
+ // options group
+ Composite optionsGroup = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout(1, false);
+ optionsGroup.setLayout(layout);
+
+ // overwrite... checkbox
+ createOverwriteExistingFilesCheckbox(optionsGroup);
+ }
+
+ protected void createOverwriteExistingFilesCheckbox(Composite optionsGroup) {
+ //Overwrite checkbox
+ overwriteExistingFilesCheckbox = new Button(optionsGroup, SWT.CHECK | SWT.LEFT);
+ overwriteExistingFilesCheckbox.setText(Messages.Export_OverwriteCheckbox);
+ overwriteExistingFilesCheckbox.setEnabled(true);
+ synchHelper.synchCheckbox(overwriteExistingFilesCheckbox,
IJ2EEComponentExportDataModelProperties.OVERWRITE_EXISTING, null);
+ }
+
+ protected String getModuleFacet() {
+ Object o = selection.getFirstElement();
+ if( o instanceof IProject ) {
+ IProject proj = (IProject)o;
+ IProjectFacet facet = VCFUtil.getModuleFacet(proj);
+ return facet == null ? null : facet.getId();
+ }
+ return null;
+ }
+
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportWizard.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportWizard.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.wtp.ui/src/org/jboss/ide/eclipse/as/wtp/ui/wizards/export/ProjectModuleExportWizard.java 2009-10-08
22:23:02 UTC (rev 17990)
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.wtp.ui.wizards.export;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IExportWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard;
+import org.jboss.ide.eclipse.as.wtp.ui.Messages;
+
+public class ProjectModuleExportWizard extends DataModelWizard
+ implements IExportWizard {
+ /**
+ * <p>
+ * Constant used to identify the key of the main page of the Wizard.
+ * </p>
+ */
+ protected static final String MAIN_PG = "main"; //$NON-NLS-1$
+
+ private IStructuredSelection currentSelection;
+
+ public ProjectModuleExportWizard() {
+ super();
+ setWindowTitle(Messages.Export_WizardTitle);
+ }
+
+ public ProjectModuleExportWizard(IDataModel model) {
+ super(model);
+ setWindowTitle(Messages.Export_WizardTitle);
+ }
+
+ protected IDataModelProvider getDefaultProvider() {
+ return new ProjectModuleExportDataModelProvider();
+ }
+
+ public void doAddPages() {
+ addPage(new ProjectModuleExportPage(getDataModel(), MAIN_PG, getSelection()));
+ }
+
+ protected void doInit() {
+ // do nothing
+ }
+
+ public final void init(IWorkbench workbench, IStructuredSelection selection) {
+ setWindowTitle(Messages.Export_WizardTitle);
+ this.currentSelection = selection;
+ }
+
+ private void doDispose() {
+ //dispose
+ }
+
+ public final void dispose() {
+ super.dispose();
+ doDispose();
+ this.currentSelection = null;
+ }
+
+ protected final boolean prePerformFinish() {
+ return super.prePerformFinish();
+ }
+
+ /**
+ * @return Returns the currentSelection.
+ */
+ protected final IStructuredSelection getSelection() {
+ return currentSelection;
+ }
+
+ /**
+ * @return
+ */
+ protected final ProjectModuleExportPage getMainPage() {
+ return (ProjectModuleExportPage) getPage(MAIN_PG);
+ }
+
+}