Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
IDE-405 IN-PROGRESS
- fixed new portlet... quick action for projects in and out of liferay project
  • Loading branch information
gamerson committed Sep 26, 2011
1 parent 0a8dc2c commit ffc0770
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 145 deletions.
Expand Up @@ -58,12 +58,14 @@ public class NewPortletClassDataModelProvider extends NewWebClassDataModelProvid
implements INewPortletClassDataModelProperties, IPluginWizardFragmentProperties {

protected Properties categories;

protected TemplateContextType contextType;

protected boolean fragment;
protected IProject initialProject;
protected TemplateStore templateStore;

protected boolean fragment;
public NewPortletClassDataModelProvider() {
super();
}

public NewPortletClassDataModelProvider(
TemplateStore templateStore, TemplateContextType contextType, boolean fragment) {
Expand All @@ -73,9 +75,76 @@ public NewPortletClassDataModelProvider(
this.contextType = contextType;
this.fragment = fragment;
}
public NewPortletClassDataModelProvider(
TemplateStore templateStore, TemplateContextType contextType, boolean fragment, IProject initialProject ) {
this( templateStore, contextType, fragment );

public NewPortletClassDataModelProvider() {
super();
this.initialProject = initialProject;
}

protected ParamValue[] createDefaultParamValuesForModes(String[] modes, String[] names, String[] values) {
Assert.isTrue(modes != null && names != null && values != null && (modes.length == names.length) &&
(names.length == values.length));

List<ParamValue> defaultParams = new ArrayList<ParamValue>();

// for each path value need to prepend a path that will be specific to
// the portlet being created
String prependPath = getDataModel().getStringProperty(CREATE_JSPS_FOLDER);

for (int i = 0; i < modes.length; i++) {
if (getBooleanProperty(modes[i])) {
ParamValue paramValue = CommonFactory.eINSTANCE.createParamValue();

paramValue.setName(names[i]);

if (CoreUtil.isNullOrEmpty(prependPath)) {
paramValue.setValue(values[i]);
}
else {
if (CoreUtil.isNullOrEmpty(prependPath) || (!prependPath.startsWith("/"))) {
prependPath = "/" + prependPath;
}
paramValue.setValue(prependPath + values[i]);
}

defaultParams.add(paramValue);
}
}

return defaultParams.toArray(new ParamValue[0]);
}

protected Properties getCategories() {
if (categories == null) {
IProject project = (IProject) getProperty(PROJECT);

if (project != null) {
try {
IRuntime runtime = null;

if (this.fragment) {
org.eclipse.wst.common.project.facet.core.runtime.IRuntime bRuntime =
(org.eclipse.wst.common.project.facet.core.runtime.IRuntime) getDataModel().getProperty(
FACET_RUNTIME);
runtime = ServerUtil.getRuntime(bRuntime);
}
else {
runtime = ServerUtil.getRuntime(project);
}

ILiferayRuntime portalRuntime = (ILiferayRuntime) runtime.createWorkingCopy().loadAdapter(
ILiferayRuntime.class, null);

categories = portalRuntime.getPortletCategories();
}
catch (Exception e) {
e.printStackTrace();
}
}
}

return categories;
}

@Override
Expand Down Expand Up @@ -171,10 +240,40 @@ else if ( QUALIFIED_CLASS_NAME.equals( propertyName ) ) {
return QUALIFIED_MVC_PORTLET;
}
}
else if ( PROJECT_NAME.equals( propertyName ) && initialProject != null ) {
return initialProject.getName();
}

return super.getDefaultProperty(propertyName);
}

protected Object getInitParams() {
List<ParamValue> initParams = new ArrayList<ParamValue>();

// if the user is using MVCPortlet and creating JSPs then we need to
// define init-params for each view mode that is checked
if (/* getStringProperty(SUPERCLASS).equals(QUALIFIED_MVC_PORTLET) && */getBooleanProperty(CREATE_JSPS)) {
String[] modes = ALL_PORTLET_MODES;

String[] names =
{
"view-jsp", "edit-jsp", "help-jsp", "about-jsp", "config-jsp", "edit-defaults-jsp",
"edit-guest-jsp", "preview-jsp", "print-jsp"
};

String[] values =
{
"/view.jsp", "/edit.jsp", "/help.jsp", "/about.jsp", "/config.jsp", "/edit-defaults.jsp",
"/edit-guest.jsp", "/preview.jsp", "/print.jsp"
};
ParamValue[] paramVals = createDefaultParamValuesForModes(modes, names, values);

Collections.addAll(initParams, paramVals);
}

return initParams;
}

@Override
public DataModelPropertyDescriptor getPropertyDescriptor(String propertyName) {
if (VIEW_MODE.equals(propertyName)) {
Expand Down Expand Up @@ -301,6 +400,19 @@ else if (CATEGORY.equals(propertyName)) {
return super.getValidPropertyDescriptors(propertyName);
}

protected IFile getWorkspaceFile(IPath file) {
IFile retval = null;

try {
retval = ResourcesPlugin.getWorkspace().getRoot().getFile(file);
}
catch (Exception e) {
// best effort
}

return retval;
}

@Override
public void init() {
super.init();
Expand Down Expand Up @@ -462,113 +574,4 @@ else if ((SUPERCLASS.equals(propertyName) || SOURCE_FOLDER.equals(propertyName))
return super.validate(propertyName);
}

protected ParamValue[] createDefaultParamValuesForModes(String[] modes, String[] names, String[] values) {
Assert.isTrue(modes != null && names != null && values != null && (modes.length == names.length) &&
(names.length == values.length));

List<ParamValue> defaultParams = new ArrayList<ParamValue>();

// for each path value need to prepend a path that will be specific to
// the portlet being created
String prependPath = getDataModel().getStringProperty(CREATE_JSPS_FOLDER);

for (int i = 0; i < modes.length; i++) {
if (getBooleanProperty(modes[i])) {
ParamValue paramValue = CommonFactory.eINSTANCE.createParamValue();

paramValue.setName(names[i]);

if (CoreUtil.isNullOrEmpty(prependPath)) {
paramValue.setValue(values[i]);
}
else {
if (CoreUtil.isNullOrEmpty(prependPath) || (!prependPath.startsWith("/"))) {
prependPath = "/" + prependPath;
}
paramValue.setValue(prependPath + values[i]);
}

defaultParams.add(paramValue);
}
}

return defaultParams.toArray(new ParamValue[0]);
}

protected Properties getCategories() {
if (categories == null) {
IProject project = (IProject) getProperty(PROJECT);

if (project != null) {
try {
IRuntime runtime = null;

if (this.fragment) {
org.eclipse.wst.common.project.facet.core.runtime.IRuntime bRuntime =
(org.eclipse.wst.common.project.facet.core.runtime.IRuntime) getDataModel().getProperty(
FACET_RUNTIME);
runtime = ServerUtil.getRuntime(bRuntime);
}
else {
runtime = ServerUtil.getRuntime(project);
}

ILiferayRuntime portalRuntime = (ILiferayRuntime) runtime.createWorkingCopy().loadAdapter(
ILiferayRuntime.class, null);

categories = portalRuntime.getPortletCategories();
}
catch (Exception e) {
e.printStackTrace();
}
}
}

return categories;
}

protected Object getInitParams() {
List<ParamValue> initParams = new ArrayList<ParamValue>();

// if the user is using MVCPortlet and creating JSPs then we need to
// define init-params for each view mode that is checked
if (/* getStringProperty(SUPERCLASS).equals(QUALIFIED_MVC_PORTLET) && */getBooleanProperty(CREATE_JSPS)) {
String[] modes = ALL_PORTLET_MODES;

String[] names =
{
"view-jsp", "edit-jsp", "help-jsp", "about-jsp", "config-jsp", "edit-defaults-jsp",
"edit-guest-jsp", "preview-jsp", "print-jsp"
};

String[] values =
{
"/view.jsp", "/edit.jsp", "/help.jsp", "/about.jsp", "/config.jsp", "/edit-defaults.jsp",
"/edit-guest.jsp", "/preview.jsp", "/print.jsp"
};
ParamValue[] paramVals = createDefaultParamValuesForModes(modes, names, values);

Collections.addAll(initParams, paramVals);
}

return initParams;
}

protected IFile getWorkspaceFile(IPath file) {
IFile retval = null;

try {
retval = ResourcesPlugin.getWorkspace().getRoot().getFile(file);
}
catch (Exception e) {
// best effort
}

return retval;
}

@Override
protected IStatus validateJavaClassName(String className) {
return super.validateJavaClassName(className);
}
}
Expand Up @@ -13,16 +13,19 @@
*
* Contributors:
* Kamesh Sampath - initial implementation
* Greg Amerson - IDE-405
******************************************************************************/

package com.liferay.ide.eclipse.portlet.ui.editor.internal;

import com.liferay.ide.eclipse.portlet.ui.editor.PortletXmlEditor;
import com.liferay.ide.eclipse.portlet.ui.wizard.NewPortletWizard;

import org.eclipse.core.resources.IProject;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.sapphire.ui.SapphireActionHandler;
import org.eclipse.sapphire.ui.SapphireRenderingContext;

import com.liferay.ide.eclipse.portlet.ui.wizard.NewPortletWizard;

/**
* @author <a href="mailto:kamesh.sampath@accenture.com">Kamesh Sampath</a>
*/
Expand All @@ -34,7 +37,14 @@ public class CreateLiferayPortletActionHandler extends SapphireActionHandler {
*/
@Override
protected Object run( SapphireRenderingContext context ) {
NewPortletWizard newPortletWizard = new NewPortletWizard();
IProject currentProject = null;

if ( context.getPart().getParentPart() instanceof PortletXmlEditor ) {
PortletXmlEditor portletXmlEditor = (PortletXmlEditor) context.getPart().getParentPart();
currentProject = portletXmlEditor.getProject();
}

NewPortletWizard newPortletWizard = new NewPortletWizard( currentProject );
WizardDialog wizardDialog = new WizardDialog( context.getShell(), newPortletWizard );
wizardDialog.create();
wizardDialog.open();
Expand Down
Expand Up @@ -13,10 +13,14 @@
*
* Contributors:
* Kamesh Sampath - initial implementation
* Greg Amerson - IDE-405
******************************************************************************/

package com.liferay.ide.eclipse.portlet.ui.editor.internal;

import com.liferay.ide.eclipse.portlet.core.model.IPortlet;
import com.liferay.ide.eclipse.project.core.util.ProjectUtil;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -30,15 +34,14 @@
import org.eclipse.sapphire.ui.SapphireAction;
import org.eclipse.sapphire.ui.SapphireActionHandler;
import org.eclipse.sapphire.ui.SapphireActionHandlerFactory;
import org.eclipse.sapphire.ui.SapphireEditor;
import org.eclipse.sapphire.ui.SapphireRenderingContext;
import org.eclipse.sapphire.ui.def.ISapphireActionHandlerDef;
import org.eclipse.sapphire.ui.def.ISapphireActionHandlerFactoryDef;
import org.eclipse.sapphire.ui.form.editors.masterdetails.MasterDetailsContentNode;
import org.eclipse.sapphire.ui.form.editors.masterdetails.MasterDetailsEditorPagePart;
import org.eclipse.swt.graphics.Image;

import com.liferay.ide.eclipse.portlet.core.model.IPortlet;

/**
* @author <a href="mailto:kamesh.sampath@accenture.com">Kamesh Sampath</a>
*/
Expand Down Expand Up @@ -69,21 +72,30 @@ public List<SapphireActionHandler> create() {

for ( int i = 0; i < this.modelProperties.length; i++ ) {
String modelProperty = this.modelProperties[i];
if ( modelProperty != null && "Portlets".equalsIgnoreCase( modelProperty ) ) {

if ( modelProperty != null && "Portlets".equalsIgnoreCase( modelProperty ) && isPartInLiferayProject() ) {
SapphireActionHandler handler = new CreateLiferayPortletActionHandler();
handler.addImage( ImageDescriptor.createFromImage( getPart().getImageCache().getImage(
IPortlet.TYPE.image() ) ) );
handler.setLabel( getActionLabel( "Portlets" ) );

listOfHandlers.add( handler );
}
else {
listOfHandlers.add( new Handler( modelProperty ) );
}
}

// System.out.println( "QuickActionsHandlerFactory.created" + listOfHandlers.size() + " handlers " );
return listOfHandlers;
}

private boolean isPartInLiferayProject() {
SapphireEditor editor = this.getPart().nearest( SapphireEditor.class );

return editor != null && ProjectUtil.isLiferayProject( editor.getProject() );
}

/**
* @author <a href="mailto:kamesh.sampath@accenture.com">Kamesh Sampath</a>
*/
Expand Down

0 comments on commit ffc0770

Please sign in to comment.