Commit 1c21452d authored by Adrien's avatar Adrien Committed by Romain Bioteau
Browse files

feat(project explorer) import export connectors from explorer (#1399)

* Import is only available on the impl folder
* Export from the impl folder -> all implementations are available
* Export from a given impl -> Only this def is available
* Export from a given def -> all the impl of this def are available

closes [BS-18958](https://bonitasoft.atlassian.net/browse/BS-18958)
parent b16ae777
......@@ -5,14 +5,12 @@
* 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
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.connector.model.implementation.provider;
......@@ -27,10 +25,8 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
/**
* @author Romain Bioteau
*
*/
public class ConnectorImplementationContentProvider implements IStructuredContentProvider {
......@@ -39,60 +35,70 @@ public class ConnectorImplementationContentProvider implements IStructuredConten
private String definitionId;
private String definitionVersion;
public ConnectorImplementationContentProvider(IRepositoryStore<IRepositoryFileStore> store ,boolean userImplementationOnly){
Assert.isTrue(store instanceof IImplementationRepositoryStore) ;
this.store = store ;
this.userImplementationOnly = userImplementationOnly ;
public ConnectorImplementationContentProvider(IRepositoryStore<IRepositoryFileStore> store,
boolean userImplementationOnly) {
Assert.isTrue(store instanceof IImplementationRepositoryStore);
this.store = store;
this.userImplementationOnly = userImplementationOnly;
}
public ConnectorImplementationContentProvider(IRepositoryStore<IRepositoryFileStore> store, String definitionId, String definitionVersion) {
Assert.isTrue(store instanceof IImplementationRepositoryStore) ;
this.store = store ;
userImplementationOnly = false ;
this.definitionId = definitionId ;
this.definitionVersion = definitionVersion ;
public ConnectorImplementationContentProvider(IRepositoryStore<IRepositoryFileStore> store, String definitionId,
String definitionVersion) {
Assert.isTrue(store instanceof IImplementationRepositoryStore);
this.store = store;
userImplementationOnly = false;
this.definitionId = definitionId;
this.definitionVersion = definitionVersion;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
@Override
public void dispose() {}
public void dispose() {
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object,
* java.lang.Object)
*/
@Override
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {}
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
@Override
public Object[] getElements(Object element) {
final List<ConnectorImplementation> connectorImplList = ((IImplementationRepositoryStore) store).getImplementations() ;
if(userImplementationOnly){
List<ConnectorImplementation> toRemove = new ArrayList<ConnectorImplementation>() ;
for(ConnectorImplementation implementation : connectorImplList){
if(implementation != null && implementation.eResource() != null){
String path = implementation.eResource().getURI().toFileString() ;
if(!path.contains(store.getResource().getLocation().toFile().getAbsolutePath())){
toRemove.add(implementation) ;
final List<ConnectorImplementation> connectorImplList = ((IImplementationRepositoryStore) store)
.getImplementations();
if (userImplementationOnly) {
List<ConnectorImplementation> toRemove = new ArrayList<>();
for (ConnectorImplementation implementation : connectorImplList) {
if (implementation != null && implementation.eResource() != null) {
String path = implementation.eResource().getURI().toFileString();
if (!path.contains(store.getResource().getLocation().toFile().getAbsolutePath())) {
toRemove.add(implementation);
}
}
}
connectorImplList.removeAll(toRemove) ;
connectorImplList.removeAll(toRemove);
}
if(definitionId != null){
final List<ConnectorImplementation> toRemove = new ArrayList<ConnectorImplementation>() ;
for(ConnectorImplementation implementation : connectorImplList){
if(implementation != null){
if(!implementation.getDefinitionId().equals(definitionId) || !implementation.getDefinitionVersion().equals(definitionVersion)){
toRemove.add(implementation) ;
if (definitionId != null) {
final List<ConnectorImplementation> toRemove = new ArrayList<>();
for (ConnectorImplementation implementation : connectorImplList) {
if (implementation != null) {
if (!implementation.getDefinitionId().equals(definitionId)
|| !implementation.getDefinitionVersion().equals(definitionVersion)) {
toRemove.add(implementation);
}
}
}
connectorImplList.removeAll(toRemove) ;
connectorImplList.removeAll(toRemove);
}
return connectorImplList.toArray(new ConnectorImplementation[connectorImplList.size()]);
}
......
......@@ -335,6 +335,70 @@
</and>
</activeWhen>
</handler>
<handler
class="org.bonitasoft.studio.connectors.handler.ImportConnectorHandler"
commandId="org.bonitasoft.studio.application.import">
<activeWhen>
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.connectors.isConnectorImplFolder">
</test>
</iterate>
</and>
</activeWhen>
</handler>
<handler
class="org.bonitasoft.studio.connectors.handler.ExportConnectorHandler"
commandId="org.bonitasoft.studio.application.export">
<activeWhen>
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.connectors.isConnectorImplFolder">
</test>
</iterate>
</and>
</activeWhen>
</handler>
<handler
class="org.bonitasoft.studio.connectors.handler.ExportSingleConnectorHandler"
commandId="org.bonitasoft.studio.application.export">
<activeWhen>
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.connectors.isConnectorImplFile">
</test>
</iterate>
</and>
</activeWhen>
</handler>
<handler
class="org.bonitasoft.studio.connectors.handler.ExportConnectorFromDefinitionHandler"
commandId="org.bonitasoft.studio.application.export">
<activeWhen>
<and>
<count
value="1">
</count>
<iterate>
<test
property="org.bonitasoft.studio.connectors.isConnectorDefFile">
</test>
</iterate>
</and>
</activeWhen>
</handler>
</extension>
<extension
point="org.eclipse.ui.commandImages">
......
/**
* Copyright (C) 2018 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.connectors.handler;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.filestore.FileStoreFinder;
import org.bonitasoft.studio.connectors.repository.ConnectorDefFileStore;
import org.bonitasoft.studio.connectors.ui.wizard.ExportConnectorWizard;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Display;
public class ExportConnectorFromDefinitionHandler extends AbstractHandler {
private RepositoryAccessor repositoryAccessor;
private FileStoreFinder fileStoreFinder;
public ExportConnectorFromDefinitionHandler() {
repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
fileStoreFinder = new FileStoreFinder();
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
fileStoreFinder.findSelectedFileStore(repositoryAccessor.getCurrentRepository())
.filter(ConnectorDefFileStore.class::isInstance)
.map(ConnectorDefFileStore.class::cast)
.map(ConnectorDefFileStore::getContent)
.ifPresent(def -> {
WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(),
new ExportConnectorWizard(def));
dialog.open();
});
return null;
}
}
/**
* Copyright (C) 2018 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.connectors.handler;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.filestore.FileStoreFinder;
import org.bonitasoft.studio.connectors.repository.ConnectorImplFileStore;
import org.bonitasoft.studio.connectors.ui.wizard.ExportConnectorWizard;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Display;
public class ExportSingleConnectorHandler extends AbstractHandler {
private RepositoryAccessor repositoryAccessor;
private FileStoreFinder fileStoreFinder;
public ExportSingleConnectorHandler() {
repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
fileStoreFinder = new FileStoreFinder();
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
fileStoreFinder
.findSelectedFileStore(repositoryAccessor.getCurrentRepository())
.filter(ConnectorImplFileStore.class::isInstance)
.map(ConnectorImplFileStore.class::cast)
.map(ConnectorImplFileStore::getContent)
.ifPresent(impl -> {
WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(),
new ExportConnectorWizard(impl));
dialog.open();
});
return null;
}
}
......@@ -2,28 +2,26 @@
/**
* Copyright (C) 2009 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
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.connectors.ui.wizard;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.store.AbstractRepositoryStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.bonitasoft.studio.connector.model.definition.ConnectorDefinition;
import org.bonitasoft.studio.connector.model.definition.IDefinitionRepositoryStore;
import org.bonitasoft.studio.connector.model.implementation.ConnectorImplementation;
import org.bonitasoft.studio.connector.model.implementation.provider.ConnectorImplementationContentProvider;
......@@ -38,40 +36,64 @@ import org.bonitasoft.studio.pics.Pics;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
/**
* @author Mickael Istria
*
*/
public class ExportConnectorWizard extends Wizard {
private ExportConnectorWizardPage exportConnectorWizardPage;
protected Optional<ConnectorImplementation> connectorImplToExport = Optional.empty();
protected Optional<ConnectorDefinition> connectorDefToExport = Optional.empty();
public ExportConnectorWizard(){
setDefaultPageImageDescriptor(Pics.getWizban()) ;
public ExportConnectorWizard() {
setDefaultPageImageDescriptor(Pics.getWizban());
setWindowTitle(Messages.exportConnectorTitle);
setNeedsProgressMonitor(true) ;
setNeedsProgressMonitor(true);
}
public ExportConnectorWizard(ConnectorImplementation connectorToExport) {
this();
this.connectorImplToExport = Optional.ofNullable(connectorToExport);
}
public ExportConnectorWizard(ConnectorDefinition connectorDefToExport) {
this();
this.connectorDefToExport = Optional.ofNullable(connectorDefToExport);
}
@Override
public void addPages() {
exportConnectorWizardPage = new ExportConnectorWizardPage(getPageTitle(),getPageDescription(),getContentProvider(),getLabelProvider(),getDefRepositoryStore());
exportConnectorWizardPage = new ExportConnectorWizardPage(getPageTitle(), getPageDescription(), getContentProvider(),
getLabelProvider(), getDefRepositoryStore());
addPage(exportConnectorWizardPage);
}
protected LabelProvider getLabelProvider() {
return new ConnectorImplementationLabelProvider((IDefinitionRepositoryStore)RepositoryManager.getInstance().getRepositoryStore(ConnectorDefRepositoryStore.class),ConnectorPlugin.getDefault().getBundle());
return new ConnectorImplementationLabelProvider(
RepositoryManager.getInstance().getRepositoryStore(ConnectorDefRepositoryStore.class),
ConnectorPlugin.getDefault().getBundle());
}
@SuppressWarnings({ "rawtypes", "unchecked" })
protected IContentProvider getContentProvider() {
ConnectorImplRepositoryStore repositoryStore = RepositoryManager.getInstance().getRepositoryStore(ConnectorImplRepositoryStore.class);
return new ConnectorImplementationContentProvider((AbstractRepositoryStore)repositoryStore,false);
protected IContentProvider getContentProvider() {
if (connectorImplToExport.isPresent()) {
return (IStructuredContentProvider) inputElement -> new ConnectorImplementation[] {
connectorImplToExport.get() };
}
IRepositoryStore repositoryStore = RepositoryManager.getInstance()
.getRepositoryStore(ConnectorImplRepositoryStore.class);
if (connectorDefToExport.isPresent()) {
ConnectorDefinition definition = connectorDefToExport.get();
return new ConnectorImplementationContentProvider(repositoryStore, definition.getId(),
definition.getVersion());
}
return new ConnectorImplementationContentProvider(repositoryStore, false);
}
protected String getPageDescription() {
......@@ -81,62 +103,60 @@ public class ExportConnectorWizard extends Wizard {
protected String getPageTitle() {
return Messages.selectConnectorImplementationToExportTitle;
}
protected IDefinitionRepositoryStore getDefRepositoryStore(){
return (IDefinitionRepositoryStore)RepositoryManager.getInstance().getRepositoryStore(ConnectorDefRepositoryStore.class);
protected IDefinitionRepositoryStore getDefRepositoryStore() {
return RepositoryManager.getInstance().getRepositoryStore(ConnectorDefRepositoryStore.class);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
@Override
public boolean performFinish() {
try {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException {
progressMonitor.beginTask(Messages.exporting, IProgressMonitor.UNKNOWN) ;
String destPathFile=exportConnectorWizardPage.getDestFilePath();
if (destPathFile.endsWith(File.separator)){
destPathFile=destPathFile+exportConnectorWizardPage.getDestFileName();
} else {
destPathFile=destPathFile+File.separator+exportConnectorWizardPage.getDestFileName(); }
final ExportConnectorArchiveOperation operation = createExportOperation(exportConnectorWizardPage.getSelectedImplementation(), exportConnectorWizardPage.isIncludeSources(), exportConnectorWizardPage.isAddDependencies(), destPathFile) ;
final IStatus status = operation.run(progressMonitor) ;
displayResult(status) ;
getContainer().run(true, false, progressMonitor -> {
progressMonitor.beginTask(Messages.exporting, IProgressMonitor.UNKNOWN);
String destPathFile = exportConnectorWizardPage.getDestFilePath();
if (destPathFile.endsWith(File.separator)) {
destPathFile = destPathFile + exportConnectorWizardPage.getDestFileName();
} else {
destPathFile = destPathFile + File.separator + exportConnectorWizardPage.getDestFileName();
}
}) ;
} catch (Exception e){
BonitaStudioLog.error(e) ;
final ExportConnectorArchiveOperation operation = createExportOperation(
exportConnectorWizardPage.getSelectedImplementation(), exportConnectorWizardPage.isIncludeSources(),
exportConnectorWizardPage.isAddDependencies(), destPathFile);
final IStatus status = operation.run(progressMonitor);
displayResult(status);
});
} catch (Exception e) {
BonitaStudioLog.error(e);
}
return true ;
return true;
}
protected void displayResult(final IStatus status) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
if(!status.isOK()){
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.exportStatusTitle, status.getMessage()) ;
}else{
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.exportStatusTitle,Messages.exportSuccessfulMsg) ;
}
Display.getDefault().syncExec(() -> {
if (!status.isOK()) {
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.exportStatusTitle,
status.getMessage());
} else {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.exportStatusTitle,
Messages.exportSuccessfulMsg);
}
}) ;
});
}
protected ExportConnectorArchiveOperation createExportOperation(ConnectorImplementation impl,boolean addSources,boolean addDependencies,String targetPath){
final ExportConnectorArchiveOperation operation = new ExportConnectorArchiveOperation() ;
operation.setImplementation(impl) ;
operation.setIncludeSources(addSources) ;
operation.setTargetPath(targetPath) ;
operation.setAddDependencies(addDependencies) ;
return operation ;
protected ExportConnectorArchiveOperation createExportOperation(ConnectorImplementation impl, boolean addSources,
boolean addDependencies, String targetPath) {
final ExportConnectorArchiveOperation operation = new ExportConnectorArchiveOperation();
operation.setImplementation(impl);
operation.setIncludeSources(addSources);
operation.setTargetPath(targetPath);
operation.setAddDependencies(addDependencies);
return operation;
}
}
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