Commit ae47de94 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub
Browse files

feat(explorer) create groovy class from explorer (#1391)

parent 4f97c262
......@@ -55,7 +55,7 @@
</menuContribution>
<menuContribution
allPopups="false"
locationURI="menu:org.bonitasoft.studio.development?after=org.bonitasoft.studio.menu.editscripts">
locationURI="menu:org.bonitasoft.studio.development?after=org.bonitasoft.studio.menu.connector">
<menu
label="%Filters"
icon="icons/actor_filter.png"
......
......@@ -1388,6 +1388,13 @@
properties="isRenamable"
type="org.eclipse.core.runtime.IAdaptable">
</propertyTester>
<propertyTester
class="org.bonitasoft.studio.application.property.tester.GroovySrcPropertyTester"
id="org.bonitasoft.studio.groovy.ui.GroovySrcPropertyTester"
namespace="org.bonitasoft.studio.groovy.ui"
properties="isGroovySrcFolder"
type="org.eclipse.core.runtime.IAdaptable">
</propertyTester>
</extension>
<extension
point="org.eclipse.ui.perspectives">
......
package org.bonitasoft.studio.application.property.tester;
import java.util.Objects;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.groovy.repository.GroovyRepositoryStore;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.core.IPackageFragment;
public class GroovySrcPropertyTester extends PropertyTester {
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
IResource adapter = ((IAdaptable) receiver).getAdapter(IResource.class);
IPackageFragment packageFragment = ((IAdaptable) receiver).getAdapter(IPackageFragment.class);
IFolder groovySrcFolder = RepositoryManager.getInstance().getRepositoryStore(GroovyRepositoryStore.class)
.getResource();
return Objects.equals(
groovySrcFolder,
adapter)
|| (packageFragment != null
&& groovySrcFolder.getLocation().isPrefixOf(packageFragment.getResource().getLocation()));
}
}
......@@ -62,7 +62,8 @@ Require-Bundle: org.junit;bundle-version="4.11.0";resolution:=optional,
org.eclipse.e4.core.di;bundle-version="1.4.0",
org.eclipse.e4.ui.services,
org.eclipse.ui.workbench.texteditor,
org.bonitasoft.studio.preferences
org.bonitasoft.studio.preferences,
org.eclipse.jdt.ui
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.bonitasoft.engine.api,
org.bonitasoft.engine.bdm.dao,
......@@ -91,3 +92,4 @@ Export-Package: org.bonitasoft.studio.groovy.ui;
org.bonitasoft.studio.groovy.ui.widgets,
org.bonitasoft.studio.groovy.ui.widgets.pojo,
org.bonitasoft.studio.groovy.ui.wizard
Bundle-ActivationPolicy: lazy
editGroovyScript_Label=Manage Groovy scripts...
\ No newline at end of file
GroovyClass=Groovy class...
\ No newline at end of file
......@@ -27,28 +27,16 @@
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.bonitasoft.studio.development?after=org.bonitasoft.studio.menu.connector">
<command
commandId="org.bonitasoft.studio.groovy.ui.editscripts"
icon="icons/manage_groovy_scripts.png"
id="org.bonitasoft.studio.menu.editscripts"
label="%editGroovyScript_Label"
style="push">
</command>
<visibleWhen
checkEnabled="true">
<reference
definitionId="isBonitaPerspectiveActive">
</reference>
</visibleWhen>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:org.bonitasoft.studio.application.project.explorer?after=group.manage.dependencies">
locationURI="popup:org.bonitasoft.studio.application.project.explorer.new?after=org.bonitasoft.studio.actors.newFilterImpl">
<separator
name="org.bonitasoft.studio.groovy.ui.separator"
visible="true">
</separator>
<command
commandId="org.bonitasoft.studio.groovy.ui.editscripts"
icon="icons/manage_groovy_scripts.png"
commandId="org.bonitasoft.studio.groovy.ui.newScript"
icon="icons/newgroovyclass_wiz.gif"
style="push">
<visibleWhen
checkEnabled="true">
......@@ -74,9 +62,8 @@
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="org.bonitasoft.studio.groovy.ui.handler.EditGroovyScriptHandler"
id="org.bonitasoft.studio.groovy.ui.editscripts"
name="%editGroovyScript_Label">
id="org.bonitasoft.studio.groovy.ui.newScript"
name="%GroovyClass">
</command>
</extension>
<extension
......@@ -105,6 +92,29 @@
<appliesTo projectNature="org.bonitasoft.studio.common.repository.bonitaNature"/>
</lookup>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.bonitasoft.studio.groovy.ui.handler.NewGroovyScript"
commandId="org.bonitasoft.studio.groovy.ui.newScript">
</handler>
<handler
class="org.bonitasoft.studio.groovy.ui.handler.NewGroovyScript"
commandId="org.bonitasoft.studio.application.newWithWizard">
<activeWhen>
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.groovy.ui.isGroovySrcFolder">
</test>
</iterate>
</and>
</activeWhen>
</handler>
</extension>
</plugin>
/**
* Copyright (C) 2018 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.groovy.ui.handler;
import org.bonitasoft.studio.common.repository.filestore.AbstractFileStore;
import org.bonitasoft.studio.groovy.ui.wizard.NewGroovyClassWizard;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.PlatformUI;
public class NewGroovyScript extends AbstractHandler {
/* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final NewGroovyClassWizard wizard = new NewGroovyClassWizard();
ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
wizard.init(PlatformUI.getWorkbench(), (IStructuredSelection) selectionService.getSelection());
new WizardDialog(Display.getDefault().getActiveShell(), wizard).open();
AbstractFileStore.refreshExplorerView();
return null;
}
}
/**
* Copyright (C) 2018 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.groovy.ui.wizard;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.groovy.repository.GroovyRepositoryStore;
import org.codehaus.groovy.eclipse.ui.decorators.GroovyPluginImages;
import org.codehaus.groovy.eclipse.wizards.NewClassWizardPage;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.wizards.NewElementWizard;
import org.eclipse.jface.viewers.IStructuredSelection;
public class NewGroovyClassWizard extends NewElementWizard {
private NewClassWizardPage fPage;
public NewGroovyClassWizard() {
super();
setWindowTitle("Create a new Groovy class.");
setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
setDefaultPageImageDescriptor(GroovyPluginImages.DESC_NEW_GROOVY_ELEMENT);
}
@Override
public void addPages() {
super.addPages();
fPage = new NewClassWizardPage();
addPage(fPage);
fPage.init(getSelection());
IJavaProject project = RepositoryManager.getInstance().getCurrentRepository().getJavaProject();
fPage.setPackageFragmentRoot(project.getPackageFragmentRoot(
RepositoryManager.getInstance().getRepositoryStore(GroovyRepositoryStore.class).getResource()), false);
IStructuredSelection selection = getSelection();
Object firstElement = selection.getFirstElement();
if (firstElement instanceof IAdaptable && ((IAdaptable) firstElement).getAdapter(IPackageFragment.class) != null) {
fPage.setPackageFragment(((IAdaptable) firstElement).getAdapter(IPackageFragment.class), true);
}
}
@Override
protected boolean canRunForked() {
return !fPage.isEnclosingTypeSelected();
}
@Override
protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
fPage.createType(monitor); // use the full progress monitor
}
@Override
public boolean performFinish() {
warnAboutTypeCommentDeprecation();
boolean res = super.performFinish();
if (res) {
IResource resource = fPage.getModifiedResource();
if (resource != null) {
selectAndReveal(resource);
openResource((IFile) resource);
}
}
return res;
}
@Override
public IJavaElement getCreatedElement() {
return fPage.getCreatedType();
}
}
......@@ -70,7 +70,6 @@ import org.bonitasoft.studio.tests.exporter.bpmn.BPMNGatewayExportImportTest;
import org.bonitasoft.studio.tests.exporter.bpmn.BPMNSequenceFlowDefaultFlowExportImportTest;
import org.bonitasoft.studio.tests.expressionEditor.TestConnectorExpression;
import org.bonitasoft.studio.tests.expressionEditor.TestPatternExpressionViewer;
import org.bonitasoft.studio.tests.groovy.TestBonitaGroovyEditorDialog;
import org.bonitasoft.studio.tests.iteration.MultiInstantiationIT;
import org.bonitasoft.studio.tests.processzoo.examples.TestWebPurchase;
import org.bonitasoft.studio.tests.properties.CallActivityMappingIT;
......@@ -114,7 +113,6 @@ import org.junit.runners.Suite;
TestOpenDiagram.class,
OpenNameAndVersionDiagramForDiagramTest.class,
ConnectorDefinitionTranslationsTest.class,
TestBonitaGroovyEditorDialog.class,
CopyPasteTests.class,
DeleteCommandTest.class,
NewRunTest.class,
......
/**
* Copyright (C) 2010-2011 BonitaSoft S.A.
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.tests.groovy;
import static org.bonitasoft.studio.dependencies.i18n.Messages.selectMissingJarTitle;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.engine.BOSEngineManager;
import org.bonitasoft.studio.swtbot.framework.conditions.AssertionCondition;
import org.bonitasoft.studio.swtbot.framework.rule.SWTGefBotRule;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(SWTBotJunit4ClassRunner.class)
public class TestBonitaGroovyEditorDialog {
private final SWTGefBot bot = new SWTGefBot();
@Rule
public SWTGefBotRule rule = new SWTGefBotRule(bot);
@Before
public void waitForEngineStarted() throws Exception {
final APISession apiSession = BOSEngineManager.getInstance().loginDefaultTenant(Repository.NULL_PROGRESS_MONITOR);
BOSEngineManager.getInstance().logoutDefaultTenant(apiSession);
}
@Ignore("fails on master ci...")
@Test
public void testOpenBonitaGroovyEditorDialog() throws ExecutionException, CoreException, IOException {
bot.menu("Development").menu("Manage Groovy scripts...").click();
bot.waitUntil(Conditions.shellIsActive("Manage Groovy scripts"));
bot.tree().setFocus();
bot.button("Create...").click();
bot.waitUntil(Conditions.shellIsActive("Create new Groovy script"));
bot.text().setText("MyTestScript");
bot.button(IDialogConstants.OK_LABEL).click();
bot.tree().getTreeItem("MyTestScript").doubleClick();
bot.waitUntil(Conditions.shellIsActive("Edit expression"));
bot.styledText().setText("\"test me\"");
bot.button("Evaluate").click();
bot.waitUntil(Conditions.shellIsActive(selectMissingJarTitle));
bot.button(IDialogConstants.OK_LABEL).click();
bot.waitUntil(Conditions.shellIsActive("Evaluation results"), 60000);
bot.waitUntil(new AssertionCondition() {
@Override
protected void makeAssert() throws Exception {
final boolean groovyEvaluateOK = "test me".equals(bot.text().getText());
if (!groovyEvaluateOK) {
bot.button(IDialogConstants.CANCEL_LABEL).click();
bot.button(IDialogConstants.OK_LABEL).click();
}
assertTrue("Error while evaluating groovy script", groovyEvaluateOK);
}
}, 10000);
bot.button(IDialogConstants.OK_LABEL).click();
if (!FileActionDialog.getDisablePopup()) {
bot.button(IDialogConstants.OK_LABEL).click();
}
bot.button(IDialogConstants.CANCEL_LABEL);
}
@After
public void closeDialog() throws Exception {
SWTBotButton button = bot.button(IDialogConstants.CANCEL_LABEL);
if (button.isEnabled()) {
button.click();
}
button = bot.button(IDialogConstants.CANCEL_LABEL);
if (button.isEnabled()) {
button.click();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment