Author: snjeza
Date: 2008-08-31 19:57:33 -0400 (Sun, 31 Aug 2008)
New Revision: 9970
Added:
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/action/
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/action/xpl/
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/action/xpl/AddJavaEEArtifactOperationEx.java
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/action/xpl/AddWebClassOperationEx.java
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/xpl/
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/xpl/NewJavaClassWizardPageEx.java
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.ui/META-INF/MANIFEST.MF
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/operations/AddPortletOperation.java
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/PortletUIActivator.java
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassDataModelProvider.java
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassOptionsWizardPage.java
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassWizardPage.java
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletWizard.java
Log:
JBIDE-2621 Portlet wizards should not be restricted to portlet enabled projects
Modified: trunk/portlet/plugins/org.jboss.tools.portlet.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/portlet/plugins/org.jboss.tools.portlet.ui/META-INF/MANIFEST.MF 2008-08-30
00:06:07 UTC (rev 9969)
+++ trunk/portlet/plugins/org.jboss.tools.portlet.ui/META-INF/MANIFEST.MF 2008-08-31
23:57:33 UTC (rev 9970)
@@ -26,5 +26,6 @@
org.eclipse.wst.xml.core,
org.eclipse.wst.sse.core,
org.eclipse.jdt.ui,
- org.eclipse.ui.ide
+ org.eclipse.ui.ide,
+ org.eclipse.ui.views
Bundle-ActivationPolicy: lazy
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/operations/AddPortletOperation.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/operations/AddPortletOperation.java 2008-08-30
00:06:07 UTC (rev 9969)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/operations/AddPortletOperation.java 2008-08-31
23:57:33 UTC (rev 9970)
@@ -10,6 +10,7 @@
import static org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.EDIT_MODE;
import static org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.HELP_MODE;
import static org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.IF_EXISTS;
+import static
org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.INITIAL_WINDOW_STATE;
import static
org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.INSTANCE_NAME;
import static
org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.IS_JSF_PORTLET;
import static
org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.IS_SEAM_PORTLET;
@@ -19,7 +20,6 @@
import static
org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.PAGE_REGION;
import static
org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.PARENT_PORTAL;
import static
org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.PORTLET_HEIGHT;
-import static
org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.INITIAL_WINDOW_STATE;
import static org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.TITLE;
import static org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.VIEW_MODE;
import static
org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties.WINDOW_NAME;
@@ -46,7 +46,6 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jst.j2ee.internal.common.operations.NewJavaEEArtifactClassOperation;
-import org.eclipse.jst.j2ee.internal.web.operations.AddWebClassOperation;
import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
@@ -64,6 +63,7 @@
import org.jboss.tools.portlet.core.PortletCoreActivator;
import org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties;
import org.jboss.tools.portlet.ui.PortletUIActivator;
+import org.jboss.tools.portlet.ui.internal.wizard.action.xpl.AddWebClassOperationEx;
import org.osgi.framework.Bundle;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -73,7 +73,7 @@
/**
* @author snjeza
*/
-public class AddPortletOperation extends AddWebClassOperation {
+public class AddPortletOperation extends AddWebClassOperationEx {
public static final IOverwriteQuery OVERWRITE_NO_QUERY = new IOverwriteQuery()
{
@@ -124,6 +124,10 @@
protected void generateMetaData(IDataModel aModel, String qualifiedClassName) {
// update the portlet.xml file
+ boolean isPortletProject = PortletUIActivator.isPortletProject(aModel);
+ if (!isPortletProject) {
+ return;
+ }
updatePortletXml(aModel);
boolean addPortlet = model.getBooleanProperty(ADD_PORTLET);
@@ -134,6 +138,11 @@
// generate/update *.object.xml
updatePortletObject(aModel);
}
+ boolean isJSFPortlet = model.getBooleanProperty(IS_JSF_PORTLET);
+ boolean isSeamPortlet = model.getBooleanProperty(IS_SEAM_PORTLET);
+ if (!isJSFPortlet && !isSeamPortlet) {
+ return;
+ }
boolean addJBossApp = model.getBooleanProperty(ADD_JBOSS_APP);
if (addJBossApp) {
updateJBossApp(aModel);
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/PortletUIActivator.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/PortletUIActivator.java 2008-08-30
00:06:07 UTC (rev 9969)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/PortletUIActivator.java 2008-08-31
23:57:33 UTC (rev 9970)
@@ -1,13 +1,21 @@
package org.jboss.tools.portlet.ui;
+import static
org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties.PROJECT_NAME;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.jboss.tools.portlet.core.IPortletConstants;
import org.jboss.tools.portlet.core.PortletCoreActivator;
import org.osgi.framework.BundleContext;
@@ -79,4 +87,27 @@
IStatus status = new Status(IStatus.ERROR,PLUGIN_ID,e.getLocalizedMessage(),e);
PortletCoreActivator.getDefault().getLog().log(status);
}
+
+ public static boolean isPortletProject(IDataModel model) {
+ String projectName = model.getStringProperty(PROJECT_NAME);
+ if(projectName != null && !"".equals(projectName.trim())){
+ IProject project = ProjectUtilities.getProject(projectName);
+ try {
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project);
+ return facetedProject != null &&
facetedProject.hasProjectFacet(getPortletFacet());
+ } catch (CoreException e) {
+ PortletUIActivator.log(e);
+ }
+ }
+ return false;
+
+ }
+
+ private static IProjectFacet getPortletFacet() {
+ try {
+ return ProjectFacetsManager.getProjectFacet(IPortletConstants.PORTLET_FACET_ID);
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
}
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassDataModelProvider.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassDataModelProvider.java 2008-08-30
00:06:07 UTC (rev 9969)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassDataModelProvider.java 2008-08-31
23:57:33 UTC (rev 9970)
@@ -2,13 +2,32 @@
+import static
org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.SOURCE_FOLDER;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+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.core.runtime.Status;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
+import org.eclipse.jem.util.logger.proxy.Logger;
+import org.eclipse.jst.j2ee.internal.common.J2EECommonMessages;
+import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
+import org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider;
+import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
import org.eclipse.jst.j2ee.internal.web.operations.INewServletClassDataModelProperties;
import org.eclipse.jst.j2ee.internal.web.operations.NewServletClassDataModelProvider;
import org.eclipse.jst.j2ee.internal.web.operations.NewServletClassOperation;
@@ -260,11 +279,57 @@
if (propertyName.equals(IF_EXISTS)) {
return "overwrite";
}
-
+ if (propertyName.equals(INewJavaClassDataModelProperties.JAVA_SOURCE_FOLDER)) {
+ return getSourceFolder();
+ }
// Otherwise check super for default value for property
return super.getDefaultProperty(propertyName);
}
+ private Object getSourceFolder() {
+ Object result = getJavaSourceFolder();
+ if (result != null) {
+ return result;
+ }
+ return getDefaultJavaSourceFolder();
+ }
+
+ @Override
+ protected IFolder getDefaultJavaSourceFolder() {
+ IProject project = getTargetProject();
+ if (project == null)
+ return null;
+ IPackageFragmentRoot[] sources = J2EEProjectUtilities.getSourceContainers(project);
+ // Try and return the first source folder
+ if (sources.length > 0) {
+ try {
+ return (IFolder) sources[0].getCorrespondingResource();
+ } catch (Exception e) {
+ return null;
+ }
+ }
+ IJavaProject javaProject = JavaCore.create(project);
+ if (javaProject == null) {
+ return null;
+ }
+ try {
+ IClasspathEntry[] entries = javaProject.getResolvedClasspath(false);
+ for (int i = 0; i < entries.length; i++) {
+ IClasspathEntry entry = entries[i];
+ if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
+ IPath path = entry.getPath();
+ IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ if (resource instanceof IFolder) {
+ return (IFolder) resource;
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ // ignore
+ }
+ return null;
+ }
+
private String getPortletPrefix() {
String prefix = null;
if (isSeamPortlet) {
@@ -365,5 +430,51 @@
}
return interfaceList;
}
+
+ @Override
+ protected boolean isAnnotationsSupported() {
+ return false;
+ }
+ @Override
+ protected IStatus validateJavaSourceFolder(String folderFullPath) {
+ // Ensure that the source folder path is not empty
+ if (folderFullPath == null || folderFullPath.length() == 0) {
+ String msg = J2EECommonMessages.ERR_JAVA_CLASS_FOLDER_NAME_EMPTY;
+ return WTPCommonPlugin.createErrorStatus(msg);
+ }
+ // Ensure that the source folder path is absolute
+ else if (!new Path(folderFullPath).isAbsolute()) {
+ String msg = J2EECommonMessages.ERR_JAVA_CLASS_FOLDER_NOT_ABSOLUTE;
+ return WTPCommonPlugin.createErrorStatus(msg);
+ }
+ IProject project = getTargetProject();
+ // Ensure project is not closed
+ if (project == null) {
+ String msg = J2EECommonMessages.ERR_JAVA_CLASS_FOLDER_NOT_EXIST;
+ return WTPCommonPlugin.createErrorStatus(msg);
+ }
+ // Ensure project is accessible.
+ if (!project.isAccessible()) {
+ String msg = J2EECommonMessages.ERR_JAVA_CLASS_FOLDER_NOT_EXIST;
+ return WTPCommonPlugin.createErrorStatus(msg);
+ }
+ // Ensure the project is a java project.
+ try {
+ if (!project.hasNature(JavaCore.NATURE_ID)) {
+ String msg = J2EECommonMessages.ERR_JAVA_CLASS_NOT_JAVA_PROJECT;
+ return WTPCommonPlugin.createErrorStatus(msg);
+ }
+ } catch (CoreException e) {
+ Logger.getLogger().log(e);
+ }
+ // Ensure the selected folder is a valid java source folder for the component
+ IFolder sourcefolder = (IFolder) getSourceFolder();
+ if (sourcefolder == null || (sourcefolder != null &&
!sourcefolder.getFullPath().equals(new Path(folderFullPath)))) {
+ String msg =
J2EECommonMessages.getResourceString(J2EECommonMessages.ERR_JAVA_CLASS_FOLDER_NOT_SOURCE,
new String[]{folderFullPath});
+ return WTPCommonPlugin.createErrorStatus(msg);
+ }
+ // Valid source is selected
+ return WTPCommonPlugin.OK_STATUS;
+ }
}
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassOptionsWizardPage.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassOptionsWizardPage.java 2008-08-30
00:06:07 UTC (rev 9969)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassOptionsWizardPage.java 2008-08-31
23:57:33 UTC (rev 9970)
@@ -1,5 +1,10 @@
package org.jboss.tools.portlet.ui.internal.wizard;
+import static
org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties.PROJECT_NAME;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -16,7 +21,12 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.jboss.tools.portlet.core.IPortletConstants;
import org.jboss.tools.portlet.ui.INewPortletClassDataModelProperties;
+import org.jboss.tools.portlet.ui.PortletUIActivator;
public class NewPortletClassOptionsWizardPage extends
NewWebClassOptionsWizardPage implements ISelectionChangedListener {
@@ -141,4 +151,10 @@
private boolean canRemoveSelectedInterfaces(IStructuredSelection selection) {
return true;
}
+
+ @Override
+ public boolean canFlipToNextPage() {
+ return isPageComplete() && PortletUIActivator.isPortletProject(model);
+ }
+
}
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassWizardPage.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassWizardPage.java 2008-08-30
00:06:07 UTC (rev 9969)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletClassWizardPage.java 2008-08-31
23:57:33 UTC (rev 9970)
@@ -10,60 +10,92 @@
* Kaloyan Raev, kaloyan.raev(a)sap.com
*******************************************************************************/
package org.jboss.tools.portlet.ui.internal.wizard;
+import static
org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel.USE_ANNOTATIONS;
+import static
org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.CLASS_NAME;
import static
org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.PROJECT;
-import static
org.eclipse.jst.j2ee.internal.web.operations.INewServletClassDataModelProperties.IS_SERVLET_TYPE;
import static
org.eclipse.jst.j2ee.internal.web.operations.INewWebClassDataModelProperties.USE_EXISTING_CLASS;
+import static
org.eclipse.jst.servlet.ui.internal.wizard.IWebWizardConstants.BROWSE_BUTTON_LABEL;
+import static
org.eclipse.jst.servlet.ui.internal.wizard.IWebWizardConstants.CLASS_NAME_LABEL;
import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
+import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.window.Window;
-import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
import org.eclipse.jst.j2ee.internal.war.ui.util.WebServletGroupItemProvider;
+import org.eclipse.jst.j2ee.internal.wizard.AnnotationsStandaloneGroup;
+import org.eclipse.jst.j2ee.internal.wizard.NewJavaClassWizardPage;
import org.eclipse.jst.j2ee.webapplication.WebApp;
import org.eclipse.jst.jee.ui.internal.navigator.web.GroupServletItemProvider;
import org.eclipse.jst.jee.ui.internal.navigator.web.WebAppProvider;
-import org.eclipse.jst.servlet.ui.internal.wizard.NewWebClassWizardPage;
+import org.eclipse.jst.servlet.ui.internal.plugin.WEBUIMessages;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.wst.common.componentcore.ComponentCore;
-import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
-import org.eclipse.wst.common.project.facet.core.internal.FacetedProject;
import org.jboss.tools.portlet.core.IPortletConstants;
import org.jboss.tools.portlet.ui.MultiSelectFilteredFileSelectionDialog;
+import org.jboss.tools.portlet.ui.internal.wizard.xpl.NewJavaClassWizardPageEx;
-public class NewPortletClassWizardPage extends NewWebClassWizardPage {
+public class NewPortletClassWizardPage extends NewJavaClassWizardPageEx {
+ protected AnnotationsStandaloneGroup annotationsGroup;
+
+ protected Button existingClassButton;
+ protected Label existingClassLabel;
+ protected Text existingClassText;
+ protected Button existingButton;
+
public NewPortletClassWizardPage(IDataModel model, String pageName, String pageDesc,
String pageTitle, String moduleType) {
super(model, pageName, pageDesc, pageTitle, moduleType);
}
@Override
+ protected Composite createTopLevelComposite(Composite parent) {
+ Composite composite = super.createTopLevelComposite(parent);
+
+ //projectNameLabel.setText(WEBUIMessages.WEB_PROJECT_LBL);
+
+ addSeperator(composite, 3);
+ createUseExistingGroup(composite);
+ //createAnnotationsGroup(composite);
+ model.setProperty(USE_ANNOTATIONS, false);
+
+ Dialog.applyDialogFont(composite);
+
+ return composite;
+ }
+
+ @Override
protected boolean isProjectValid(IProject project) {
- boolean result = super.isProjectValid(project);
- if (result == false) {
- return result;
- }
+ boolean result;
try {
- result = FacetedProjectFramework.hasProjectFacet(project,
IPortletConstants.PORTLET_FACET_ID);
+ result = project.isAccessible() &&
+ project.hasNature(JavaCore.NATURE_ID);
} catch (CoreException ce) {
result = false;
}
return result;
+
}
- @Override
+
protected String getUseExistingCheckboxText() {
return "Use an existing Portlet class";
}
- @Override
+
protected String getUseExistingProperty() {
return USE_EXISTING_CLASS;
}
@@ -83,7 +115,6 @@
return super.getExtendedSelectedProject(selection);
}
- @Override
protected void handleClassButtonSelected() {
getControl().setCursor(new Cursor(getShell().getDisplay(), SWT.CURSOR_WAIT));
IProject project = (IProject) model.getProperty(PROJECT);
@@ -109,4 +140,52 @@
getControl().setCursor(null);
}
+ private void createUseExistingGroup(Composite composite) {
+ existingButton = new Button(composite, SWT.CHECK);
+ existingButton.setText(getUseExistingCheckboxText());
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ data.horizontalSpan = 3;
+ existingButton.setLayoutData(data);
+ synchHelper.synchCheckbox(existingButton, getUseExistingProperty(), null);
+ existingButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ handleExistingButtonSelected();
+ }
+ });
+
+ existingClassLabel = new Label(composite, SWT.LEFT);
+ existingClassLabel.setText(CLASS_NAME_LABEL);
+ existingClassLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
+ existingClassLabel.setEnabled(false);
+
+ existingClassText = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY);
+ existingClassText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ existingClassText.setEnabled(false);
+ synchHelper.synchText(existingClassText, CLASS_NAME, null);
+
+ existingClassButton = new Button(composite, SWT.PUSH);
+ existingClassButton.setText(BROWSE_BUTTON_LABEL);
+ existingClassButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+ existingClassButton.setEnabled(false);
+ existingClassButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ handleClassButtonSelected();
+ }
+ });
+ }
+
+ private void handleExistingButtonSelected() {
+ boolean enable = existingButton.getSelection();
+ existingClassLabel.setEnabled(enable);
+ existingClassButton.setEnabled(enable);
+ packageText.setEnabled(!enable);
+ packageButton.setEnabled(!enable);
+ packageLabel.setEnabled(!enable);
+ classText.setEnabled(!enable);
+ classLabel.setEnabled(!enable);
+ superText.setEnabled(!enable);
+ superButton.setEnabled(!enable);
+ superLabel.setEnabled(!enable);
+ }
+
}
Modified:
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletWizard.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletWizard.java 2008-08-30
00:06:07 UTC (rev 9969)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/NewPortletWizard.java 2008-08-31
23:57:33 UTC (rev 9970)
@@ -49,15 +49,16 @@
IPortletUIConstants.NEW_PORTLET_WIZARD_PAGE_TITLE, IModuleConstants.JST_WEB_MODULE);
//page1.setInfopopID(IWebUIContextIds.WEBEDITOR_SERVLET_PAGE_ADD_SERVLET_WIZARD_1);
addPage(page1);
- AddPortletWizardPage page2 = new AddPortletWizardPage(getDataModel(), PAGE_TWO);
- //page2.setInfopopID(IWebUIContextIds.WEBEDITOR_SERVLET_PAGE_ADD_SERVLET_WIZARD_2);
- addPage(page2);
- NewPortletClassOptionsWizardPage page3 = new NewPortletClassOptionsWizardPage(
+
+ NewPortletClassOptionsWizardPage page2 = new NewPortletClassOptionsWizardPage(
getDataModel(),
- PAGE_THREE,
+ PAGE_TWO,
"Specify modifiers, interfaces to implement and method stubs to
generate.",
IPortletUIConstants.NEW_PORTLET_WIZARD_PAGE_TITLE);
//page3.setInfopopID(IWebUIContextIds.WEBEDITOR_SERVLET_PAGE_ADD_SERVLET_WIZARD_3);
+ addPage(page2);
+ AddPortletWizardPage page3 = new AddPortletWizardPage(getDataModel(), PAGE_THREE);
+ //page2.setInfopopID(IWebUIContextIds.WEBEDITOR_SERVLET_PAGE_ADD_SERVLET_WIZARD_2);
addPage(page3);
AddJBossPortletWizardPage page4 = new AddJBossPortletWizardPage(getDataModel(),
PAGE_FOUR);
addPage(page4);
Added:
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/action/xpl/AddJavaEEArtifactOperationEx.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/action/xpl/AddJavaEEArtifactOperationEx.java
(rev 0)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/action/xpl/AddJavaEEArtifactOperationEx.java 2008-08-31
23:57:33 UTC (rev 9970)
@@ -0,0 +1,119 @@
+package org.jboss.tools.portlet.ui.internal.wizard.action.xpl;
+
+import static
org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.CLASS_NAME;
+import static
org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.JAVA_PACKAGE;
+import static
org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties.PROJECT_NAME;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
+import org.eclipse.jst.j2ee.internal.common.operations.NewJavaEEArtifactClassOperation;
+import org.eclipse.jst.j2ee.model.IModelProvider;
+import org.eclipse.jst.j2ee.model.ModelProviderManager;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.jboss.tools.portlet.ui.PortletUIActivator;
+
+public abstract class AddJavaEEArtifactOperationEx extends AbstractDataModelOperation {
+
+ protected IModelProvider provider;
+
+ public AddJavaEEArtifactOperationEx(IDataModel dataModel) {
+ super(dataModel);
+ }
+
+ @Override
+ public IStatus execute(final IProgressMonitor monitor, final IAdaptable info) throws
ExecutionException {
+ Runnable runnable = null;
+ provider = getModelProvider();
+ runnable = new Runnable(){
+ public void run() {
+ try {
+ doExecute(monitor, info);
+ } catch (ExecutionException e) {
+ PortletUIActivator.log(e);
+ }
+ }
+ };
+ if (provider != null) {
+ if (provider.validateEdit(null, null).isOK()) {
+
+ provider.modify(runnable, null);
+ }
+ } else {
+ runnable.run();
+ }
+ //return doExecute(monitor, info);
+ return Status.CANCEL_STATUS;
+ }
+
+ private IModelProvider getModelProvider() {
+ IModelProvider modelProvider = null;
+ try {
+ modelProvider = ModelProviderManager.getModelProvider(getTargetProject());
+ } catch (Throwable e) {
+ // ignore
+ }
+ return modelProvider;
+ }
+
+ public IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+ // create the java class
+ createClass();
+ return OK_STATUS;
+ }
+
+ protected String createClass() {
+ // Create bean java class file using the NewBeanClassOperation.
+ NewJavaEEArtifactClassOperation op = getNewClassOperation();
+ try {
+ IStatus status = op.execute(new NullProgressMonitor(), null);
+ if (!status.isOK()) {
+ PortletUIActivator.getDefault().getLog().log(status);
+ }
+ } catch (Exception e) {
+ PortletUIActivator.log(e);
+ }
+ // Return the qualified class name of the newly created java class for
+ // the bean
+ return getQualifiedClassName();
+ }
+
+ protected abstract NewJavaEEArtifactClassOperation getNewClassOperation();
+
+ public IProject getTargetProject() {
+ String projectName = model.getStringProperty(PROJECT_NAME);
+ return ProjectUtilities.getProject(projectName);
+ }
+
+ /**
+ * This method will return the qualified java class name as specified by the
+ * class name and package name properties in the data model. This method
+ * should not return null.
+ *
+ * @see #CLASS_NAME
+ * @see #JAVA_PACKAGE
+ *
+ * @return String qualified java class name
+ */
+ public final String getQualifiedClassName() {
+ // Use the java package name and unqualified class name to create a
+ // qualified java class name
+ String packageName = model.getStringProperty(JAVA_PACKAGE);
+ String className = model.getStringProperty(CLASS_NAME);
+
+ // Ensure the class is not in the default package before adding package
+ // name to qualified name
+ if (packageName != null && packageName.trim().length() > 0)
+ return packageName + "." + className; //$NON-NLS-1$
+
+ return className;
+ }
+
+}
Added:
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/action/xpl/AddWebClassOperationEx.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/action/xpl/AddWebClassOperationEx.java
(rev 0)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/action/xpl/AddWebClassOperationEx.java 2008-08-31
23:57:33 UTC (rev 9970)
@@ -0,0 +1,64 @@
+package org.jboss.tools.portlet.ui.internal.wizard.action.xpl;
+
+import static
org.eclipse.jst.j2ee.application.internal.operations.IAnnotationsDataModel.USE_ANNOTATIONS;
+import static
org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties.CLASS_NAME;
+import static
org.eclipse.jst.j2ee.internal.web.operations.INewWebClassDataModelProperties.USE_EXISTING_CLASS;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jst.j2ee.internal.web.operations.AddFilterOperation;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+
+public abstract class AddWebClassOperationEx extends AddJavaEEArtifactOperationEx {
+
+ public AddWebClassOperationEx(IDataModel dataModel) {
+ super(dataModel);
+ }
+
+ /**
+ * Subclasses may extend this method to add their own actions during
+ * execution. The implementation of the execute method drives the running of
+ * the operation. This implementation will create the filter class, and
+ * then it will create the filter metadata for the web deployment descriptor.
+ * This method will accept null as a parameter.
+ *
+ * @see
org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor,
+ * org.eclipse.core.runtime.IAdaptable)
+ * @see AddFilterOperation#createFilterClass()
+ * @see AddFilterOperation#generateFilterMetaData(NewFilterClassDataModel,
+ * String)
+ *
+ * @param monitor
+ * IProgressMonitor
+ * @param info
+ * IAdaptable
+ * @throws CoreException
+ * @throws InterruptedException
+ * @throws InvocationTargetException
+ */
+ @Override
+ public IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+
+ boolean useExisting = model.getBooleanProperty(USE_EXISTING_CLASS);
+ String qualifiedClassName = model.getStringProperty(CLASS_NAME);
+
+ // create the java class
+ if (!useExisting)
+ qualifiedClassName = createClass();
+
+ // If the filter is not annotated, generate the filter metadata for the DD
+ if (!model.getBooleanProperty(USE_ANNOTATIONS))
+ generateMetaData(model, qualifiedClassName);
+
+ return OK_STATUS;
+ }
+
+ protected abstract void generateMetaData(IDataModel aModel, String qualifiedClassName);
+
+}
Added:
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/xpl/NewJavaClassWizardPageEx.java
===================================================================
---
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/xpl/NewJavaClassWizardPageEx.java
(rev 0)
+++
trunk/portlet/plugins/org.jboss.tools.portlet.ui/src/org/jboss/tools/portlet/ui/internal/wizard/xpl/NewJavaClassWizardPageEx.java 2008-08-31
23:57:33 UTC (rev 9970)
@@ -0,0 +1,719 @@
+package org.jboss.tools.portlet.ui.internal.wizard.xpl;
+
+/*******************************************************************************
+ * Copyright (c) 2003, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ * David Schneider, david.schneider(a)unisys.com - [142500] WTP properties pages fonts
don't follow Eclipse preferences
+ *******************************************************************************/
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
+import org.eclipse.jdt.internal.ui.viewsupport.IViewPartInputProvider;
+import org.eclipse.jdt.ui.JavaElementLabelProvider;
+import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties;
+import org.eclipse.jst.j2ee.internal.dialogs.TypeSearchEngine;
+import org.eclipse.jst.j2ee.internal.plugin.J2EEUIMessages;
+import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Cursor;
+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.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.dialogs.ISelectionStatusValidator;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.ui.views.contentoutline.ContentOutline;
+import
org.eclipse.wst.common.componentcore.internal.operation.IArtifactEditOperationDataModelProperties;
+import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage;
+import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
+import org.jboss.tools.portlet.ui.PortletUIActivator;
+
+/**
+ *
+ */
+public class NewJavaClassWizardPageEx extends DataModelWizardPage {
+
+ private Text folderText;
+ private Button folderButton;
+ protected Text packageText;
+ protected Button packageButton;
+ protected Label packageLabel;
+ protected Text classText;
+ protected Label classLabel;
+ protected Text superText;
+ protected Button superButton;
+ protected Label superLabel;
+ protected Label projectNameLabel;
+ private Combo projectNameCombo;
+ protected String projectType;
+ private String projectName;
+
+ /**
+ * @param model
+ * @param pageName
+ */
+ public NewJavaClassWizardPageEx(IDataModel model, String pageName, String pageDesc,
String pageTitle,
+ String moduleType) {
+ super(model, pageName);
+ setDescription(pageDesc);
+ this.setTitle(pageTitle);
+ setPageComplete(false);
+ this.projectType = moduleType;
+ this.projectName = null;
+ }
+
+ /**
+ *
+ */
+ protected String[] getValidationPropertyNames() {
+ return new String[]{IArtifactEditOperationDataModelProperties.PROJECT_NAME,
+ IArtifactEditOperationDataModelProperties.COMPONENT_NAME,
+ INewJavaClassDataModelProperties.SOURCE_FOLDER,
+ INewJavaClassDataModelProperties.JAVA_PACKAGE,
+ INewJavaClassDataModelProperties.CLASS_NAME,
+ INewJavaClassDataModelProperties.SUPERCLASS};
+ }
+
+ /**
+ *
+ */
+ protected Composite createTopLevelComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 3;
+ composite.setLayout(layout);
+ GridData data = new GridData();
+ data.verticalAlignment = GridData.FILL;
+ data.horizontalAlignment = GridData.FILL;
+ data.widthHint = 300;
+ composite.setLayoutData(data);
+
+ addProjectNameGroup(composite);
+ addFolderGroup(composite);
+ addSeperator(composite, 3);
+ addPackageGroup(composite);
+ addClassnameGroup(composite);
+ addSuperclassGroup(composite);
+
+ classText.setFocus();
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, getInfopopID());
+ Dialog.applyDialogFont(parent);
+ return composite;
+ }
+
+ /**
+ * Add project group
+ */
+ private void addProjectNameGroup(Composite parent) {
+ // set up project name label
+ projectNameLabel = new Label(parent, SWT.NONE);
+ projectNameLabel.setText(J2EEUIMessages.getResourceString(J2EEUIMessages.MODULES_DEPENDENCY_PAGE_TABLE_PROJECT));
//$NON-NLS-1$
+ GridData data = new GridData();
+ projectNameLabel.setLayoutData(data);
+ // set up project name entry field
+ projectNameCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ data.widthHint = 300;
+ data.horizontalSpan = 1;
+ projectNameCombo.setLayoutData(data);
+ projectNameCombo.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ super.widgetSelected(e);
+ // update source folder
+ if (folderText != null) {
+ String sourceFolder =
getDefaultJavaSourceFolder(ProjectUtilities.getProject(projectNameCombo.getText())).getFullPath().toOSString();
+ if (sourceFolder != null)
+ folderText.setText(sourceFolder);
+ }
+ }
+ });
+ synchHelper.synchCombo(projectNameCombo,
IArtifactEditOperationDataModelProperties.PROJECT_NAME, null);
+ initializeProjectList();
+ new Label(parent, SWT.NONE);
+ }
+
+ /**
+ *
+ **/
+ private IFolder getDefaultJavaSourceFolder(IProject project) {
+
+ if (project == null)
+ return null;
+ IPackageFragmentRoot[] sources = J2EEProjectUtilities.getSourceContainers(project);
+ // Try and return the first source folder
+ if (sources.length > 0) {
+ try {
+ return (IFolder) sources[0].getCorrespondingResource();
+ } catch (Exception e) {
+ return null;
+ }
+ }
+ IJavaProject javaProject = JavaCore.create(project);
+ if (javaProject == null) {
+ return null;
+ }
+ try {
+ IClasspathEntry[] entries = javaProject.getResolvedClasspath(false);
+ for (int i = 0; i < entries.length; i++) {
+ IClasspathEntry entry = entries[i];
+ if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
+ IPath path = entry.getPath();
+ IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ if (resource instanceof IFolder) {
+ return (IFolder) resource;
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ // ignore
+ }
+ return null;
+ }
+
+ /**
+ * This method is used by the project list initializer. The method checks
+ * if the specified project is valid to include it in the project list.
+ *
+ * <p>Subclasses of this wizard page should override this method to
+ * adjust filtering of the projects to their needs. </p>
+ *
+ * @param project reference to the project to be checked
+ *
+ * @return <code>true</code> if the project is valid to be included in
+ * the project list, <code>false</code> - otherwise.
+ */
+ protected boolean isProjectValid(IProject project) {
+ boolean result;
+ try {
+ result = project.isAccessible() &&
+ project.hasNature(IModuleConstants.MODULE_NATURE_ID) &&
+ J2EEProjectUtilities.getJ2EEProjectType(project).equals(projectType);
+ } catch (CoreException ce) {
+ result = false;
+ }
+ return result;
+ }
+
+ /**
+ *
+ */
+ private void initializeProjectList() {
+ IProject[] workspaceProjects = ProjectUtilities.getAllProjects();
+ List items = new ArrayList();
+ for (int i = 0; i < workspaceProjects.length; i++) {
+ IProject project = workspaceProjects[i];
+ if (isProjectValid(project))
+ items.add(project.getName());
+ }
+ if (items.isEmpty()) return;
+ String[] names = new String[items.size()];
+ for (int i = 0; i < items.size(); i++) {
+ names[i] = (String) items.get(i);
+ }
+ projectNameCombo.setItems(names);
+ IProject selectedProject = null;
+ try {
+ if (model !=null) {
+ String projectNameFromModel =
model.getStringProperty(IArtifactEditOperationDataModelProperties.COMPONENT_NAME);
+ if (projectNameFromModel!=null && projectNameFromModel.length()>0)
+ selectedProject = ProjectUtilities.getProject(projectNameFromModel);
+ }
+ } catch (Exception e) {};
+ try {
+ if (selectedProject == null)
+ selectedProject = getSelectedProject();
+ if (selectedProject != null && selectedProject.isAccessible()
+ && selectedProject.hasNature(IModuleConstants.MODULE_NATURE_ID)) {
+ projectNameCombo.setText(selectedProject.getName());
+ model.setProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME,
selectedProject.getName());
+ }
+ } catch (CoreException ce) {
+ // Ignore
+ }
+ if (projectName == null && names.length > 0)
+ projectName = names[0];
+
+ if ((projectNameCombo.getText() == null || projectNameCombo.getText().length() == 0)
&& projectName != null) {
+ projectNameCombo.setText(projectName);
+ model.setProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME,
projectName);
+ }
+
+ }
+
+ /**
+ * Add folder group to composite
+ */
+ private void addFolderGroup(Composite composite) {
+ // folder
+ Label folderLabel = new Label(composite, SWT.LEFT);
+ folderLabel.setText(J2EEUIMessages.FOLDER_LABEL);
+ folderLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+
+ folderText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+ folderText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ synchHelper.synchText(folderText, INewJavaClassDataModelProperties.SOURCE_FOLDER,
null);
+
+ IPackageFragmentRoot root = getSelectedPackageFragmentRoot();
+ String projectName =
model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME);
+ if (projectName != null && projectName.length() > 0) {
+ IProject targetProject = ProjectUtilities.getProject(projectName);
+ if (root == null || !root.getJavaProject().getProject().equals(targetProject)) {
+ IFolder folder = getDefaultJavaSourceFolder(targetProject);
+ if (folder != null)
+ folderText.setText(folder.getFullPath().toOSString());
+ } else {
+ folderText.setText(root.getPath().toString());
+ }
+ }
+
+ folderButton = new Button(composite, SWT.PUSH);
+ folderButton.setText(J2EEUIMessages.BROWSE_BUTTON_LABEL);
+ folderButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+ folderButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ handleFolderButtonPressed();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Do nothing
+ }
+ });
+ }
+
+ /**
+ * Add package group to composite
+ */
+ private void addPackageGroup(Composite composite) {
+ // package
+ packageLabel = new Label(composite, SWT.LEFT);
+ packageLabel.setText(J2EEUIMessages.JAVA_PACKAGE_LABEL);
+ packageLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+
+ packageText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+ packageText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ synchHelper.synchText(packageText, INewJavaClassDataModelProperties.JAVA_PACKAGE,
null);
+
+ IPackageFragment packageFragment = getSelectedPackageFragment();
+ String targetProject =
model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME);
+ if (packageFragment != null && packageFragment.exists() &&
+ packageFragment.getJavaProject().getElementName().equals(targetProject)) {
+ IPackageFragmentRoot root = getPackageFragmentRoot(packageFragment);
+ if (root != null)
+ folderText.setText(root.getPath().toString());
+ model.setProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE,
packageFragment.getElementName());
+ }
+
+ packageButton = new Button(composite, SWT.PUSH);
+ packageButton.setText(J2EEUIMessages.BROWSE_BUTTON_LABEL);
+ packageButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+ packageButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ handlePackageButtonPressed();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Do nothing
+ }
+ });
+ }
+
+ protected IPackageFragmentRoot getPackageFragmentRoot(IPackageFragment packageFragment)
{
+ if (packageFragment == null)
+ return null;
+ else if (packageFragment.getParent() instanceof IPackageFragment)
+ return getPackageFragmentRoot((IPackageFragment) packageFragment.getParent());
+ else if (packageFragment.getParent() instanceof IPackageFragmentRoot)
+ return (IPackageFragmentRoot) packageFragment.getParent();
+ else
+ return null;
+ }
+
+ /**
+ * Add classname group to composite
+ */
+ private void addClassnameGroup(Composite composite) {
+ // class name
+ classLabel = new Label(composite, SWT.LEFT);
+ classLabel.setText(J2EEUIMessages.CLASS_NAME_LABEL);
+ classLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+
+ classText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+ classText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ synchHelper.synchText(classText, INewJavaClassDataModelProperties.CLASS_NAME, null);
+
+ new Label(composite, SWT.LEFT);
+ }
+
+ /**
+ * Add seperator to composite
+ */
+ protected void addSeperator(Composite composite, int horSpan) {
+ GridData data = new GridData();
+ data.verticalAlignment = GridData.FILL;
+ data.horizontalAlignment = GridData.FILL;
+ data.widthHint = 300;
+ // Separator label
+ Label seperator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
+ data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ data.horizontalSpan = horSpan;
+ seperator.setLayoutData(data);
+ }
+
+ /**
+ * Add superclass group to the composite
+ */
+ private void addSuperclassGroup(Composite composite) {
+ // superclass
+ superLabel = new Label(composite, SWT.LEFT);
+ superLabel.setText(J2EEUIMessages.SUPERCLASS_LABEL);
+ superLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+
+ superText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+ superText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ synchHelper.synchText(superText, INewJavaClassDataModelProperties.SUPERCLASS, null);
+
+ superButton = new Button(composite, SWT.PUSH);
+ superButton.setText(J2EEUIMessages.BROWSE_BUTTON_LABEL);
+ superButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+ superButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ handleSuperButtonPressed();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Do nothing
+ }
+ });
+ }
+
+ /**
+ * Browse for a new Destination Folder
+ */
+ protected void handleFolderButtonPressed() {
+ ISelectionStatusValidator validator = getContainerDialogSelectionValidator();
+ ViewerFilter filter = getContainerDialogViewerFilter();
+ ITreeContentProvider contentProvider = new WorkbenchContentProvider();
+ ILabelProvider labelProvider = new DecoratingLabelProvider(new
WorkbenchLabelProvider(), PlatformUI.getWorkbench()
+ .getDecoratorManager().getLabelDecorator());
+ ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(),
labelProvider, contentProvider);
+ dialog.setValidator(validator);
+ dialog.setTitle(J2EEUIMessages.CONTAINER_SELECTION_DIALOG_TITLE);
+ dialog.setMessage(J2EEUIMessages.CONTAINER_SELECTION_DIALOG_DESC);
+ dialog.addFilter(filter);
+ String projectName =
model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME);
+ if (projectName==null || projectName.length()==0)
+ return;
+ IProject project = ProjectUtilities.getProject(projectName);
+ dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
+
+ if (project != null)
+ dialog.setInitialSelection(project);
+ if (dialog.open() == Window.OK) {
+ Object element = dialog.getFirstResult();
+ try {
+ if (element instanceof IContainer) {
+ IContainer container = (IContainer) element;
+ folderText.setText(container.getFullPath().toString());
+ // dealWithSelectedContainerResource(container);
+ }
+ } catch (Exception ex) {
+ // Do nothing
+ }
+
+ }
+ }
+
+ protected void handlePackageButtonPressed() {
+ IPackageFragmentRoot packRoot = (IPackageFragmentRoot)
model.getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT);
+ if (packRoot == null)
+ return;
+ IJavaElement[] packages = null;
+ try {
+ packages = packRoot.getChildren();
+ } catch (JavaModelException e) {
+ // Do nothing
+ }
+ if (packages == null)
+ packages = new IJavaElement[0];
+
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new
JavaElementLabelProvider(
+ JavaElementLabelProvider.SHOW_DEFAULT));
+ dialog.setTitle(J2EEUIMessages.PACKAGE_SELECTION_DIALOG_TITLE);
+ dialog.setMessage(J2EEUIMessages.PACKAGE_SELECTION_DIALOG_DESC);
+ dialog.setEmptyListMessage(J2EEUIMessages.PACKAGE_SELECTION_DIALOG_MSG_NONE);
+ dialog.setElements(packages);
+ if (dialog.open() == Window.OK) {
+ IPackageFragment fragment = (IPackageFragment) dialog.getFirstResult();
+ if (fragment != null) {
+ packageText.setText(fragment.getElementName());
+ } else {
+ packageText.setText(J2EEUIMessages.EMPTY_STRING);
+ }
+ }
+ }
+
+ protected void handleSuperButtonPressed() {
+ getControl().setCursor(new Cursor(getShell().getDisplay(), SWT.CURSOR_WAIT));
+ IPackageFragmentRoot packRoot = (IPackageFragmentRoot)
model.getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT);
+ if (packRoot == null)
+ return;
+
+ // this eliminates the non-exported classpath entries
+ final IJavaSearchScope scope =
TypeSearchEngine.createJavaSearchScopeForAProject(packRoot.getJavaProject(), true, true);
+
+ // This includes all entries on the classpath. This behavior is
+ // identical
+ // to the Super Class Browse Button on the Create new Java Class Wizard
+ // final IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new
+ // IJavaElement[] {root.getJavaProject()} );
+ FilteredTypesSelectionDialog dialog = new
FilteredTypesSelectionDialog(getShell(),false, getWizard().getContainer(), scope,
IJavaSearchConstants.CLASS);
+ dialog.setTitle(J2EEUIMessages.SUPERCLASS_SELECTION_DIALOG_TITLE);
+ dialog.setMessage(J2EEUIMessages.SUPERCLASS_SELECTION_DIALOG_DESC);
+
+ if (dialog.open() == Window.OK) {
+ IType type = (IType) dialog.getFirstResult();
+ String superclassFullPath = J2EEUIMessages.EMPTY_STRING;
+ if (type != null) {
+ superclassFullPath = type.getFullyQualifiedName();
+ }
+ superText.setText(superclassFullPath);
+ getControl().setCursor(null);
+ return;
+ }
+ getControl().setCursor(null);
+ }
+
+ /**
+ * Returns a new instance of the Selection validator for the Container
+ * Selection Dialog This method can be extended by subclasses, as it does
+ * some basic validation.
+ */
+ protected ISelectionStatusValidator getContainerDialogSelectionValidator() {
+ return new ISelectionStatusValidator() {
+ public IStatus validate(Object[] selection) {
+ if (selection != null && selection[0] != null && !(selection[0]
instanceof IProject))
+ return WTPCommonPlugin.OK_STATUS;
+ return
WTPCommonPlugin.createErrorStatus(J2EEUIMessages.CONTAINER_SELECTION_DIALOG_VALIDATOR_MESG);
+ }
+ };
+ }
+
+ /**
+ * Returns a new instance of the Selection Listner for the Container
+ * Selection Dialog
+ */
+ protected ViewerFilter getContainerDialogViewerFilter() {
+ return new ViewerFilter() {
+ public boolean select(Viewer viewer, Object parent, Object element) {
+ if (element instanceof IProject) {
+ IProject project = (IProject) element;
+ return
project.getName().equals(model.getProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME));
+ } else if (element instanceof IFolder) {
+ IFolder folder = (IFolder) element;
+ // only show source folders
+ IProject project =
ProjectUtilities.getProject(model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME));
+ IPackageFragmentRoot[] sourceFolders =
J2EEProjectUtilities.getSourceContainers(project);
+ for (int i = 0; i < sourceFolders.length; i++) {
+ if (sourceFolders[i].getResource()!= null &&
sourceFolders[i].getResource().equals(folder))
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+ }
+
+
+
+ /**
+ * @return
+ */
+ private IProject getSelectedProject() {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null)
+ return null;
+ ISelection selection = window.getSelectionService().getSelection();
+ if (selection == null)
+ return null;
+ if (!(selection instanceof IStructuredSelection))
+ return null;
+ IStructuredSelection stucturedSelection = (IStructuredSelection) selection;
+ if (stucturedSelection.getFirstElement() instanceof EObject)
+ return ProjectUtilities.getProject(stucturedSelection.getFirstElement());
+ IJavaElement element = getInitialJavaElement(selection);
+ if (element != null && element.getJavaProject() != null)
+ return element.getJavaProject().getProject();
+ return getExtendedSelectedProject(stucturedSelection.getFirstElement());
+ }
+
+ protected IProject getExtendedSelectedProject(Object selection) {
+ return null;
+ }
+
+ /**
+ * @return
+ */
+ private IPackageFragment getSelectedPackageFragment() {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null)
+ return null;
+ ISelection selection = window.getSelectionService().getSelection();
+ if (selection == null)
+ return null;
+ IJavaElement element = getInitialJavaElement(selection);
+ if (element != null) {
+ if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
+ return (IPackageFragment) element;
+ } else if (element.getElementType() == IJavaElement.COMPILATION_UNIT) {
+ IJavaElement parent = ((ICompilationUnit) element).getParent();
+ if (parent.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
+ return (IPackageFragment) parent;
+ }
+ } else if (element.getElementType() == IJavaElement.TYPE) {
+ return ((IType) element).getPackageFragment();
+ }
+ }
+ return null;
+ }
+
+ private IPackageFragmentRoot getSelectedPackageFragmentRoot() {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null)
+ return null;
+ ISelection selection = window.getSelectionService().getSelection();
+ if (selection == null)
+ return null;
+ // StructuredSelection stucturedSelection = (StructuredSelection)
+ // selection;
+ IJavaElement element = getInitialJavaElement(selection);
+ if (element != null) {
+ if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT)
+ return (IPackageFragmentRoot) element;
+ }
+ return null;
+ }
+
+ /**
+ * Utility method to inspect a selection to find a Java element.
+ *
+ * @param selection
+ * the selection to be inspected
+ * @return a Java element to be used as the initial selection, or
+ * <code>null</code>, if no Java element exists in the given
+ * selection
+ */
+ protected IJavaElement getInitialJavaElement(ISelection selection) {
+ IJavaElement jelem = null;
+ if (selection != null && !selection.isEmpty() && selection instanceof
IStructuredSelection) {
+ Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
+ if (selectedElement instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable) selectedElement;
+
+ jelem = (IJavaElement) adaptable.getAdapter(IJavaElement.class);
+ if (jelem == null) {
+ IResource resource = (IResource) adaptable.getAdapter(IResource.class);
+ if (resource != null && resource.getType() != IResource.ROOT) {
+ while (jelem == null && resource.getType() != IResource.PROJECT) {
+ resource = resource.getParent();
+ jelem = (IJavaElement) resource.getAdapter(IJavaElement.class);
+ }
+ if (jelem == null) {
+ jelem = JavaCore.create(resource); // java project
+ }
+ }
+ }
+ }
+ }
+ if (jelem == null) {
+ IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window == null)
+ return null;
+ IWorkbenchPart part = window.getActivePage().getActivePart();
+ if (part instanceof ContentOutline) {
+ part = window.getActivePage().getActiveEditor();
+ }
+
+ if (part instanceof IViewPartInputProvider) {
+ Object elem = ((IViewPartInputProvider) part).getViewPartInput();
+ if (elem instanceof IJavaElement) {
+ jelem = (IJavaElement) elem;
+ }
+ }
+ }
+
+ if (jelem == null || jelem.getElementType() == IJavaElement.JAVA_MODEL) {
+ try {
+ IJavaProject[] projects = JavaCore.create(getWorkspaceRoot()).getJavaProjects();
+ if (projects.length == 1) {
+ jelem = projects[0];
+ }
+ } catch (JavaModelException e) {
+ PortletUIActivator.log(e);
+ }
+ }
+ return jelem;
+ }
+
+ protected IWorkspaceRoot getWorkspaceRoot() {
+ return ResourcesPlugin.getWorkspace().getRoot();
+ }
+
+ public void setProjectName(String projectName) {
+ this.projectName = projectName;
+ }
+
+}