Commit 27addf71 authored by Adrien's avatar Adrien Committed by Romain Bioteau

feat(project explorer) create layout from explorer (#1373)

Closes [BS-18926](https://bonitasoft.atlassian.net/browse/BS-18926)
parent 1bba2b52
......@@ -3,9 +3,11 @@
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_tWbyINKdEeaEE_Umqe0dXA" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Command" xmi:id="_-GtjsMAPEeijxe6wc4bgxQ" elementId="org.bonitasoft.studio.designer.command.create.page" commandName="%newApplicationPage"/>
<elements xsi:type="commands:Command" xmi:id="_RmPtgMugEeij9PSrVhURgw" elementId="org.bonitasoft.studio.designer.command.create.widget" commandName="%newCustomWidget"/>
<elements xsi:type="commands:Command" xmi:id="_PCN_0MvHEeij9PSrVhURgw" elementId="org.bonitasoft.studio.designer.command.create.layout" commandName="%newLayout"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_--2aUNKdEeaEE_Umqe0dXA" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler" xmi:id="_DARToMAQEeijxe6wc4bgxQ" elementId="org.bonitasoft.studio.designer.handler.create.page" contributionURI="bundleclass://org.bonitasoft.studio.designer/org.bonitasoft.studio.designer.ui.handler.CreatePageHandler" command="_-GtjsMAPEeijxe6wc4bgxQ"/>
<elements xsi:type="commands:Handler" xmi:id="_Z9WiYMugEeij9PSrVhURgw" elementId="org.bonitasoft.studio.designer.handler.create.widget" contributionURI="bundleclass://org.bonitasoft.studio.designer/org.bonitasoft.studio.designer.ui.handler.CreateCustomWidgetHandler" command="_RmPtgMugEeij9PSrVhURgw"/>
<elements xsi:type="commands:Handler" xmi:id="_YD7Q4MvHEeij9PSrVhURgw" elementId="org.bonitasoft.studio.designer.handler.create.layout" contributionURI="bundleclass://org.bonitasoft.studio.designer/org.bonitasoft.studio.designer.ui.handler.CreateLayoutHandler" command="_PCN_0MvHEeij9PSrVhURgw"/>
</fragments>
</fragment:ModelFragments>
......@@ -48,4 +48,6 @@ migratingUID=Migrating UI Designer artifacts...
creatingNewPage=Creating new page...
createPageFailed=An error occurred while creating a new application page.
creatingNewWidget=Creating new custom widget...
createWidgetFailed=An error occurred while creating a new custom widget
\ No newline at end of file
createWidgetFailed=An error occurred while creating a new custom widget
creatingNewLayout=Creating new layout...
createLayoutFailed=An error occurred while creating a new layout
......@@ -4,4 +4,5 @@ CaseStartFormMapping=Instantiation form
OverviewFormMapping=Overview page
createNewFormLabel=<A>Create a new form...</A>
newApplicationPage=Application page...
newCustomWidget=Custom widget...
\ No newline at end of file
newCustomWidget=Custom widget...
newLayout=Layout...
......@@ -15,9 +15,9 @@
allPopups="false"
locationURI="popup:org.bonitasoft.studio.application.project.explorer.new?after=org.bonitasoft.studio.application.placeholder.uidartifact">
<command
commandId="org.bonitasoft.studio.designer.command.create.widget"
icon="icons/custom_widget.png"
label="%newCustomWidget"
commandId="org.bonitasoft.studio.designer.command.create.page"
icon="icons/page.png"
label="%newApplicationPage"
style="push">
<visibleWhen
checkEnabled="true">
......@@ -38,14 +38,34 @@
</and>
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:org.bonitasoft.studio.application.project.explorer.new?after=org.bonitasoft.studio.application.placeholder.uidartifact">
<command
commandId="org.bonitasoft.studio.designer.command.create.page"
commandId="org.bonitasoft.studio.designer.command.create.layout"
icon="icons/page.png"
label="%newApplicationPage"
label="%newLayout"
style="push">
<visibleWhen
checkEnabled="true">
<and>
<count
value="1">
</count>
<or>
<iterate>
<instanceof
value="org.eclipse.core.resources.IProject">
</instanceof>
<test
property="org.bonitasoft.studio.application.isBonitaProject">
</test>
</iterate>
</or>
</and>
</visibleWhen>
</command>
<command
commandId="org.bonitasoft.studio.designer.command.create.widget"
icon="icons/custom_widget.png"
label="%newCustomWidget"
style="push">
<visibleWhen
checkEnabled="true">
......@@ -67,6 +87,46 @@
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:org.bonitasoft.studio.application.project.explorer.new?after=additions">
<command
commandId="org.bonitasoft.studio.designer.command.create.page"
label="%newApplicationPage"
style="push">
<visibleWhen
checkEnabled="true">
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.designer.isWebPageFolder">
</test>
</iterate>
</and>
</visibleWhen>
</command>
<command
commandId="org.bonitasoft.studio.designer.command.create.layout"
label="%newLayout"
style="push">
<visibleWhen
checkEnabled="true">
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.designer.isWebPageFolder">
</test>
</iterate>
</and>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
......@@ -189,22 +249,6 @@
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.bonitasoft.studio.designer.ui.handler.CreatePageHandler"
commandId="org.bonitasoft.studio.application.new">
<activeWhen>
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.designer.isWebPageFolder">
</test>
</iterate>
</and>
</activeWhen>
</handler>
<handler
class="org.bonitasoft.studio.designer.ui.handler.CreateCustomWidgetHandler"
commandId="org.bonitasoft.studio.application.new">
......
/**
* 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.designer.core.operation;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.designer.core.PageDesignerURLFactory;
import org.bonitasoft.studio.designer.core.repository.WebPageFileStore;
import org.bonitasoft.studio.designer.core.repository.WebPageRepositoryStore;
import org.bonitasoft.studio.designer.i18n.Messages;
import org.bonitasoft.studio.ui.util.StringIncrementer;
import org.eclipse.core.runtime.IProgressMonitor;
import org.json.JSONObject;
import org.restlet.ext.json.JsonRepresentation;
public class CreateLayoutOperation extends CreateUIDArtifactOperation {
private RepositoryAccessor repositoryAccessor;
public CreateLayoutOperation(PageDesignerURLFactory pageDesignerURLBuilder, RepositoryAccessor repositoryAccessor) {
super(pageDesignerURLBuilder);
this.repositoryAccessor = repositoryAccessor;
}
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask(Messages.creatingNewLayout, IProgressMonitor.UNKNOWN);
setArtifactName(getNewName());
JSONObject bodyObject = createBody();
try {
responseObject = createArtifact(pageDesignerURLBuilder.newPage(), new JsonRepresentation(bodyObject));
} catch (MalformedURLException e) {
throw new InvocationTargetException(e, "Failed to create new page URL.");
}
openArtifact(getNewArtifactId());
}
@Override
protected ArtifactyType getArtifactType() {
return ArtifactyType.LAYOUT;
}
private String getNewName() {
List<String> existingLayouts = repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class).getChildren()
.stream()
.filter(store -> Objects.equals(store.getType(), "layout"))
.map(WebPageFileStore::getDisplayName)
.collect(Collectors.toList());
return StringIncrementer.getIncrementedString(DEFAULT_LAYOUT_NAME, existingLayouts);
}
}
......@@ -17,6 +17,7 @@ package org.bonitasoft.studio.designer.core.operation;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
......@@ -59,6 +60,7 @@ public class CreatePageOperation extends CreateUIDArtifactOperation {
private String getNewName() {
List<String> existingPages = repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class).getChildren()
.stream()
.filter(store -> Objects.equals(store.getType(), "page"))
.map(WebPageFileStore::getDisplayName)
.collect(Collectors.toList());
return StringIncrementer.getIncrementedString(DEFAULT_PAGE_NAME, existingPages);
......
......@@ -25,7 +25,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;
import org.bonitasoft.studio.common.repository.filestore.AbstractFileStore;
import org.bonitasoft.studio.designer.core.PageDesignerURLFactory;
import org.bonitasoft.studio.preferences.browser.OpenBrowserOperation;
import org.eclipse.jface.operation.IRunnableWithProgress;
......@@ -38,10 +37,11 @@ import org.restlet.resource.ResourceException;
public abstract class CreateUIDArtifactOperation implements IRunnableWithProgress {
public static final String DEFAULT_PAGE_NAME = "newPage";
public static final String DEFAULT_LAYOUT_NAME = "newLayout";
public static final String DEFAULT_WIDGET_NAME = "newWidget";
enum ArtifactyType {
PAGE("page"), FORM("form"), WIDGET("widget");
PAGE("page"), FORM("form"), WIDGET("widget"), LAYOUT("layout");
private String type;
......@@ -103,6 +103,7 @@ public abstract class CreateUIDArtifactOperation implements IRunnableWithProgres
try {
switch (getArtifactType()) {
case FORM:
case LAYOUT:
case PAGE:
new OpenBrowserOperation(pageDesignerURLBuilder.openPage(artifactId)).execute();
break;
......@@ -111,7 +112,6 @@ public abstract class CreateUIDArtifactOperation implements IRunnableWithProgres
default:
break;
}
AbstractFileStore.refreshExplorerView();
} catch (final MalformedURLException e) {
throw new InvocationTargetException(e, "Failed to create open artifact URL.");
}
......
......@@ -74,6 +74,8 @@ public class Messages extends NLS {
public static String createPageFailed;
public static String creatingNewWidget;
public static String createWidgetFailed;
public static String creatingNewLayout;
public static String createLayoutFailed;
static {
NLS.initializeMessages("messages", Messages.class);
......
/**
* 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.designer.ui.handler;
import java.lang.reflect.InvocationTargetException;
import javax.inject.Named;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.designer.core.PageDesignerURLFactory;
import org.bonitasoft.studio.designer.core.operation.CreateLayoutOperation;
import org.bonitasoft.studio.designer.i18n.Messages;
import org.bonitasoft.studio.ui.dialog.ExceptionDialogHandler;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
public class CreateLayoutHandler {
@Execute
public void createLayout(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, PageDesignerURLFactory urlFactory,
RepositoryAccessor repositoryAccessor) {
CreateLayoutOperation operation = new CreateLayoutOperation(urlFactory, repositoryAccessor);
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
try {
progressService.run(true, false, operation);
} catch (InvocationTargetException | InterruptedException e) {
new ExceptionDialogHandler().openErrorDialog(shell, Messages.createLayoutFailed, e);
}
}
}
......@@ -23,17 +23,13 @@ import org.bonitasoft.studio.designer.core.PageDesignerURLFactory;
import org.bonitasoft.studio.designer.core.operation.CreatePageOperation;
import org.bonitasoft.studio.designer.i18n.Messages;
import org.bonitasoft.studio.ui.dialog.ExceptionDialogHandler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
public class CreatePageHandler extends AbstractHandler {
public class CreatePageHandler {
@Execute
public void createPage(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, PageDesignerURLFactory urlFactory,
......@@ -47,12 +43,4 @@ public class CreatePageHandler extends AbstractHandler {
}
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
RepositoryAccessor repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
createPage(Display.getDefault().getActiveShell(), PageDesignerURLFactory.INSTANCE, repositoryAccessor);
return null;
}
}
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