Skip to content

Commit

Permalink
IDE-379 add actions for invoking SDK project import wizards from SDKs in
Browse files Browse the repository at this point in the history
workspace or from individual folders that are actually liferay projects
  • Loading branch information
gamerson committed Jun 29, 2011
1 parent e5e1e4c commit 3ec154f
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 7 deletions.
Expand Up @@ -724,6 +724,11 @@ public static boolean isLiferayPluginType(String type) {
ISDKConstants.LAYOUTTPL_PLUGIN_PROJECT_SUFFIX.endsWith(type) || ISDKConstants.THEME_PLUGIN_PROJECT_SUFFIX.endsWith(type));
}

public static boolean isLiferayProject( IFolder folder ) {
return folder != null && folder.exists() && folder.getRawLocation() != null &&
isLiferayProjectDir( folder.getRawLocation().toFile() );
}

public static boolean isLiferayProject(IProject project) {
boolean retval = false;

Expand Down Expand Up @@ -805,6 +810,14 @@ public static boolean isPortletProject(IProject project) {
return hasFacet(project, IPluginFacetConstants.LIFERAY_PORTLET_PROJECT_FACET);
}

public static boolean isSDKProject( IProject project ) {
if (project == null || (!project.exists()) || (!project.isAccessible())) {
return false;
}

return SDKUtil.isValidSDKLocation( project.getLocation().toOSString() );
}

public static boolean isThemeProject(IProject project) {
return hasFacet(project, IPluginFacetConstants.LIFERAY_THEME_FACET_ID);
}
Expand Down
Expand Up @@ -76,6 +76,13 @@
properties="isLiferayProject"
type="org.eclipse.core.resources.IProject">
</propertyTester>
<propertyTester
class="com.liferay.ide.eclipse.project.ui.SDKProjectPropertyTester"
id="com.liferay.ide.eclipse.project.ui.isSDKProject"
namespace="com.liferay.ide.eclipse.project.ui"
properties="isSDKProject"
type="org.eclipse.core.resources.IProject">
</propertyTester>
<propertyTester
class="com.liferay.ide.eclipse.project.ui.ProjectNaturePropertyTester"
id="com.liferay.ide.eclipse.project.ui.hasNature"
Expand All @@ -90,6 +97,13 @@
properties="isServiceFile"
type="org.eclipse.core.resources.IFile">
</propertyTester>
<propertyTester
class="com.liferay.ide.eclipse.project.ui.LiferayProjectPropertyTester"
id="com.liferay.ide.eclipse.project.ui.isLiferayProjectFolder"
namespace="com.liferay.ide.eclipse.project.ui"
properties="isLiferayProjectFolder"
type="org.eclipse.core.resources.IFolder">
</propertyTester>
</extension>
<extension
point="org.eclipse.ui.keywords">
Expand Down Expand Up @@ -127,7 +141,7 @@
</extension>
<extension
point="org.eclipse.ui.popupMenus">
<objectContribution objectClass="org.eclipse.core.resources.IProject" adaptable="true" id="com.liferay.ide.eclipse.ui.popupmenu">
<objectContribution objectClass="org.eclipse.core.resources.IResource" adaptable="true" id="com.liferay.ide.eclipse.ui.popupmenu">
<menu
icon="icons/e16/liferay.png"
id="liferayPopupMenuCategory"
Expand Down Expand Up @@ -208,6 +222,43 @@
</enablement>

</objectContribution>
<objectContribution
adaptable="true"
id="com.liferay.ide.eclipse.project.ui.importSDKProjects"
objectClass="org.eclipse.core.resources.IProject">
<action
class="com.liferay.ide.eclipse.project.ui.action.SDKProjectsImportAction"
enablesFor="1"
icon="icons/e16/import.png"
id="com.liferay.ide.eclipse.project.ui.sdk.projects.import"
label="Import Liferay Projects..."
menubarPath="liferayPopupMenuCategory/slot1">
</action>
<enablement>
<adapt type="org.eclipse.core.resources.IProject">
<test
property="com.liferay.ide.eclipse.project.ui.isSDKProject" />
</adapt>
</enablement>
</objectContribution>
<objectContribution
adaptable="true"
id="com.liferay.ide.eclipse.project.ui.existingLiferayProject"
objectClass="org.eclipse.core.resources.IFolder">
<action
class="com.liferay.ide.eclipse.project.ui.action.ImportLiferayProjectAction"
enablesFor="1"
icon="icons/e16/import.png"
id="com.liferay.ide.eclipse.project.ui.import.liferay.project"
label="Import Liferay Project..."
menubarPath="liferayPopupMenuCategory/slot1">
</action>
<enablement>
<adapt type="org.eclipse.core.resources.IFolder">
<test property="com.liferay.ide.eclipse.project.ui.isLiferayProjectFolder" />
</adapt>
</enablement>
</objectContribution>

</extension>
<extension
Expand Down
Expand Up @@ -18,6 +18,7 @@
import com.liferay.ide.eclipse.project.core.util.ProjectUtil;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;

/**
Expand All @@ -29,6 +30,9 @@ public boolean test(Object receiver, String property, Object[] args, Object expe
if (receiver instanceof IProject) {
return ProjectUtil.isLiferayProject((IProject) receiver);
}
else if ( receiver instanceof IFolder ) {
return ProjectUtil.isLiferayProject( (IFolder) receiver );
}

return false;
}
Expand Down
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
*******************************************************************************/

package com.liferay.ide.eclipse.project.ui;

import com.liferay.ide.eclipse.project.core.util.ProjectUtil;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IProject;

/**
* @author Greg Amerson
*/
public class SDKProjectPropertyTester extends PropertyTester {

public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (receiver instanceof IProject) {
return ProjectUtil.isSDKProject( (IProject) receiver );
}

return false;
}

}
@@ -0,0 +1,85 @@
/*******************************************************************************
* Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
*******************************************************************************/

package com.liferay.ide.eclipse.project.ui.action;

import com.liferay.ide.eclipse.project.ui.wizard.LiferayProjectImportWizard;

import org.eclipse.core.resources.IFolder;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

/**
* @author Greg Amerson
*/
public class ImportLiferayProjectAction implements IObjectActionDelegate {

private ISelection fSelection;

public ImportLiferayProjectAction() {
}

public Display getDisplay() {
Display display = Display.getCurrent();

if (display == null)
display = Display.getDefault();

return display;
}

public void run(IAction action) {

if (fSelection instanceof IStructuredSelection) {
Object[] elems = ((IStructuredSelection) fSelection).toArray();

IFolder folder = null;

Object elem = elems[0];

if ( elem instanceof IFolder ) {
folder = (IFolder) elem;
}

LiferayProjectImportWizard wizard = new LiferayProjectImportWizard( folder );

final Display display = getDisplay();

final WizardDialog dialog = new WizardDialog(display.getActiveShell(), wizard);

BusyIndicator.showWhile(display, new Runnable() {

public void run() {
dialog.open();
}
});
}

}

public void selectionChanged(IAction action, ISelection selection) {
fSelection = selection;
}

public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}

}
@@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
*******************************************************************************/

package com.liferay.ide.eclipse.project.ui.action;

import com.liferay.ide.eclipse.project.ui.wizard.SDKProjectsImportWizard;
import com.liferay.ide.eclipse.sdk.SDKManager;

import org.eclipse.core.resources.IProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

/**
* @author Greg Amerson
*/
public class SDKProjectsImportAction implements IObjectActionDelegate {

private ISelection fSelection;

public SDKProjectsImportAction() {
}

public Display getDisplay() {
Display display = Display.getCurrent();

if (display == null)
display = Display.getDefault();

return display;
}

public void run(IAction action) {

if (fSelection instanceof IStructuredSelection) {
Object[] elems = ((IStructuredSelection) fSelection).toArray();

IProject project = null;

Object elem = elems[0];

if (elem instanceof IProject) {
project = (IProject) elem;
}

SDKProjectsImportWizard wizard =
new SDKProjectsImportWizard( SDKManager.getInstance().getSDK( project.getLocation() ) );

final Display display = getDisplay();

final WizardDialog dialog = new WizardDialog(display.getActiveShell(), wizard);

BusyIndicator.showWhile(display, new Runnable() {

public void run() {
dialog.open();
}
});
}

}

public void selectionChanged(IAction action, ISelection selection) {
fSelection = selection;
}

public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}

}
Expand Up @@ -19,6 +19,7 @@
import com.liferay.ide.eclipse.project.ui.ProjectUIPlugin;
import com.liferay.ide.eclipse.ui.wizard.INewProjectWizard;

import org.eclipse.core.resources.IFolder;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWizard;
Expand All @@ -33,9 +34,10 @@
public class LiferayProjectImportWizard extends DataModelWizard implements IWorkbenchWizard, INewProjectWizard {

protected LiferayProjectImportWizardPage liferayProjectImportWizardPage;
protected IFolder folder;

public LiferayProjectImportWizard() {
this(null);
this( (IDataModel) null );
}

public LiferayProjectImportWizard(IDataModel dataModel) {
Expand All @@ -47,6 +49,12 @@ public LiferayProjectImportWizard(IDataModel dataModel) {
setNeedsProgressMonitor(true);
}

public LiferayProjectImportWizard( IFolder folder ) {
this( (IDataModel) null );

this.folder = folder;
}

@Override
public boolean canFinish() {
return getDataModel().isValid();
Expand All @@ -57,8 +65,18 @@ public void init(IWorkbench workbench, IStructuredSelection selection) {

@Override
protected void doAddPages() {
if (folder != null) {
IDataModel model = getDataModel();
model.setProperty(
LiferayProjectImportDataModelProvider.PROJECT_LOCATION, folder.getRawLocation().toOSString() );

}

liferayProjectImportWizardPage = new LiferayProjectImportWizardPage(getDataModel(), "pageOne", this);
liferayProjectImportWizardPage.setWizard(this);

if ( folder != null ) {
liferayProjectImportWizardPage.updateProjectRecord( folder.getRawLocation().toOSString() );
}

addPage(liferayProjectImportWizardPage);
}
Expand Down
Expand Up @@ -217,7 +217,7 @@ protected void handleFileBrowseButton(final Text text) {
}
}

protected void updateProjectRecord(String projectLocation) {
protected void updateProjectRecord( String projectLocation ) {
if (CoreUtil.isNullOrEmpty(projectLocation)) {
return;
}
Expand Down

0 comments on commit 3ec154f

Please sign in to comment.