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

feat(explorer) add import/export organization menu (#1341)

Closes BS-18864
parent fb885b86
......@@ -59,7 +59,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.bonitasoft.studio.ui,
org.eclipse.e4.ui.model.workbench;bundle-version="2.0.0.v20170228-1842",
org.eclipse.e4.core.di.annotations,
org.eclipse.e4.core.commands
org.eclipse.e4.core.commands,
org.eclipse.core.expressions;bundle-version="3.6.0"
Import-Package: org.bonitasoft.engine.api,
org.bonitasoft.engine.bpm,
org.bonitasoft.engine.bpm.bar,
......
......@@ -377,6 +377,42 @@
</reference>
</activeWhen>
</handler>
<handler
class="org.bonitasoft.studio.actors.ui.handler.ImportOrganizationHandler"
commandId="org.bonitasoft.studio.application.import">
<activeWhen>
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.actors.isOrganizationFolder">
</test>
</iterate>
</and>
</activeWhen>
</handler>
<handler
class="org.bonitasoft.studio.actors.ui.handler.ExportOrganizationHandler"
commandId="org.bonitasoft.studio.application.export">
<activeWhen>
<and>
<count
value="1">
</count>
<iterate>
<or>
<test
property="org.bonitasoft.studio.actors.isOrganizationFolder">
</test>
<test
property="org.bonitasoft.studio.actors.isOrganizationFile">
</test></or>
</iterate>
</and>
</activeWhen>
</handler>
</extension>
<extension
id="org.bonitasoft.studio.actors.fragment"
......@@ -385,5 +421,15 @@
uri="fragment.e4xmi">
</fragment>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="org.bonitasoft.studio.actors.ui.handler.OrganizationPropertyTester"
id="org.bonitasoft.studio.actors.organizationTester"
namespace="org.bonitasoft.studio.actors"
properties="isOrganizationFolder,isOrganizationFile"
type="org.eclipse.core.runtime.IAdaptable">
</propertyTester>
</extension>
</plugin>
......@@ -17,9 +17,12 @@
package org.bonitasoft.studio.actors.ui.handler;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.repository.OrganizationFileStore;
import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.common.repository.CommonRepositoryPlugin;
import org.bonitasoft.studio.common.repository.RepositoryManager;
......@@ -28,25 +31,51 @@ import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.PlatformUI;
/**
* @author Romain Bioteau
*
*/
public class ExportOrganizationHandler 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 IRepositoryStore<? extends IRepositoryFileStore> organizationStore = RepositoryManager.getInstance().getRepositoryStore(OrganizationRepositoryStore.class) ;
List<IRepositoryStore<? extends IRepositoryFileStore>> stores = new ArrayList<IRepositoryStore<? extends IRepositoryFileStore>>() ;
stores.add(organizationStore) ;
CommonRepositoryPlugin.exportArtifactsToFile(stores, null,Messages.exportOrganizationTitle) ;
CommonRepositoryPlugin.exportArtifactsToFile(stores, getSelection(), Messages.exportOrganizationTitle);
return null;
}
private Set<Object> getSelection() {
Set<Object> res = new HashSet<>();
ISelectionService service = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
if (service == null) {
return res;
}
ISelection selection = service.getSelection();
if (selection instanceof IStructuredSelection
&& ((IStructuredSelection) selection).size() == 1) {
Object sel = ((IStructuredSelection) selection).getFirstElement();
if (sel instanceof IAdaptable && ((IAdaptable) sel).getAdapter(IResource.class) != null) {
IResource adapter = ((IAdaptable) sel).getAdapter(IResource.class);
if (adapter instanceof IFile) {
IRepositoryFileStore fileStore = RepositoryManager.getInstance().getCurrentRepository()
.getFileStore(adapter);
if (fileStore instanceof OrganizationFileStore) {
res.add(fileStore);
}
}
}
}
return res;
}
}
......@@ -29,6 +29,8 @@ import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.ui.dialog.MultiStatusDialog;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
......@@ -43,18 +45,14 @@ import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
public class ImportOrganizationHandler {
public class ImportOrganizationHandler extends AbstractHandler {
/*
* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Execute
public void execute(RepositoryAccessor repositoryAccessor) throws ExecutionException {
final OrganizationRepositoryStore organizationStore = repositoryAccessor
.getRepositoryStore(OrganizationRepositoryStore.class);
final FileDialog fd = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN);
fd.setFilterExtensions(new String[] { "*.xml;*.zip" });
fd.setFilterExtensions(new String[] { "*.xml" });
final String filePath = fd.open();
if (filePath != null) {
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
......@@ -138,4 +136,13 @@ public class ImportOrganizationHandler {
protected IStatus validateImportedOrganization(final OrganizationFileStore fileStore) {
return new OrganizationValidator().validate(fileStore.getContent());
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
RepositoryAccessor repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
execute(repositoryAccessor);
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.actors.ui.handler;
import java.util.Objects;
import org.bonitasoft.studio.actors.repository.OrganizationFileStore;
import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
public class OrganizationPropertyTester extends PropertyTester {
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (Objects.equals("isOrganizationFolder", property)) {
IResource adapter = ((IAdaptable) receiver).getAdapter(IResource.class);
return Objects.equals(
RepositoryManager.getInstance().getRepositoryStore(OrganizationRepositoryStore.class).getResource(),
adapter);
} else if (Objects.equals("isOrganizationFile", property)) {
IResource adapter = ((IAdaptable) receiver).getAdapter(IResource.class);
return RepositoryManager.getInstance().getCurrentRepository()
.getFileStore(adapter) instanceof OrganizationFileStore;
}
return false;
}
}
......@@ -52,4 +52,6 @@ openUidLog=Bonita UI-Designer log
projectExplorer=Project explorer
new=New
Open=Open
deploy=Deploy
\ No newline at end of file
deploy=Deploy
import=Import...
export=Export...
\ No newline at end of file
......@@ -489,6 +489,28 @@
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:org.bonitasoft.studio.application.project.explorer?after=group.import">
<command
commandId="org.bonitasoft.studio.application.import"
style="push">
<visibleWhen
checkEnabled="true">
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:org.bonitasoft.studio.application.project.explorer?after=group.export">
<command
commandId="org.bonitasoft.studio.application.export"
style="push">
<visibleWhen
checkEnabled="true">
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
......@@ -600,6 +622,14 @@
id="org.bonitasoft.studio.deployCommand"
name="%deploy">
</command>
<command
id="org.bonitasoft.studio.application.import"
name="%import">
</command>
<command
id="org.bonitasoft.studio.application.export"
name="%export">
</command>
</extension>
<extension
point="org.eclipse.ui.views">
......
......@@ -78,6 +78,8 @@ public class CustomPopupMenuExtender implements IMenuListener2,
INCLUDES.add("team.main");
INCLUDES.add("org.eclipse.ui.file.refresh");
INCLUDES.add("org.eclipse.jdt.junit.junitShortcut.run");
INCLUDES.add("org.eclipse.ui.file.import");
INCLUDES.add("org.eclipse.ui.file.export");
}
/**
......
......@@ -70,7 +70,7 @@
<command
commandId="org.bonitasoft.studio.exportBosArchive"
icon="icons/export.png"
label="%exportBosArchive"
label="%export"
style="push">
<visibleWhen
checkEnabled="true">
......
......@@ -2,4 +2,5 @@ import_BOS_desc=Import processes designed with Bonita Studio 6.x and 7.x (.bos)
import_BOS_Name=Bonita 6.x and 7.x
importBosCommandLabel=BOS archive...
importWorkspaceCommandLabel=Workspace...
importBosArchive=Import BOS archive
\ No newline at end of file
importBosArchive=Import BOS archive
import=Import...
\ No newline at end of file
......@@ -40,7 +40,7 @@
<command
commandId="org.bonitasoft.studio.importer.bos.command"
icon="icons/import.png"
label="%importBosArchive"
label="%import"
style="push">
<visibleWhen
checkEnabled="true">
......
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