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 @@ ...@@ -5,14 +5,12 @@
* it under the terms of the GNU General Public License as published by * 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 * the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version. * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * 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. * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License * 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; package org.bonitasoft.studio.connector.model.implementation.provider;
...@@ -27,10 +25,8 @@ import org.eclipse.core.runtime.Assert; ...@@ -27,10 +25,8 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
/** /**
* @author Romain Bioteau * @author Romain Bioteau
*
*/ */
public class ConnectorImplementationContentProvider implements IStructuredContentProvider { public class ConnectorImplementationContentProvider implements IStructuredContentProvider {
...@@ -39,60 +35,70 @@ public class ConnectorImplementationContentProvider implements IStructuredConten ...@@ -39,60 +35,70 @@ public class ConnectorImplementationContentProvider implements IStructuredConten
private String definitionId; private String definitionId;
private String definitionVersion; private String definitionVersion;
public ConnectorImplementationContentProvider(IRepositoryStore<IRepositoryFileStore> store ,boolean userImplementationOnly){ public ConnectorImplementationContentProvider(IRepositoryStore<IRepositoryFileStore> store,
Assert.isTrue(store instanceof IImplementationRepositoryStore) ; boolean userImplementationOnly) {
this.store = store ; Assert.isTrue(store instanceof IImplementationRepositoryStore);
this.userImplementationOnly = userImplementationOnly ; this.store = store;
this.userImplementationOnly = userImplementationOnly;
} }
public ConnectorImplementationContentProvider(IRepositoryStore<IRepositoryFileStore> store, String definitionId, String definitionVersion) { public ConnectorImplementationContentProvider(IRepositoryStore<IRepositoryFileStore> store, String definitionId,
Assert.isTrue(store instanceof IImplementationRepositoryStore) ; String definitionVersion) {
this.store = store ; Assert.isTrue(store instanceof IImplementationRepositoryStore);
userImplementationOnly = false ; this.store = store;
this.definitionId = definitionId ; userImplementationOnly = false;
this.definitionVersion = definitionVersion ; this.definitionId = definitionId;
this.definitionVersion = definitionVersion;
} }
/* (non-Javadoc) /*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#dispose() * @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/ */
@Override @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 @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) * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/ */
@Override @Override
public Object[] getElements(Object element) { public Object[] getElements(Object element) {
final List<ConnectorImplementation> connectorImplList = ((IImplementationRepositoryStore) store).getImplementations() ; final List<ConnectorImplementation> connectorImplList = ((IImplementationRepositoryStore) store)
if(userImplementationOnly){ .getImplementations();
List<ConnectorImplementation> toRemove = new ArrayList<ConnectorImplementation>() ; if (userImplementationOnly) {
for(ConnectorImplementation implementation : connectorImplList){ List<ConnectorImplementation> toRemove = new ArrayList<>();
if(implementation != null && implementation.eResource() != null){ for (ConnectorImplementation implementation : connectorImplList) {
String path = implementation.eResource().getURI().toFileString() ; if (implementation != null && implementation.eResource() != null) {
if(!path.contains(store.getResource().getLocation().toFile().getAbsolutePath())){ String path = implementation.eResource().getURI().toFileString();
toRemove.add(implementation) ; if (!path.contains(store.getResource().getLocation().toFile().getAbsolutePath())) {
toRemove.add(implementation);
} }
} }
} }
connectorImplList.removeAll(toRemove) ; connectorImplList.removeAll(toRemove);
} }
if(definitionId != null){ if (definitionId != null) {
final List<ConnectorImplementation> toRemove = new ArrayList<ConnectorImplementation>() ; final List<ConnectorImplementation> toRemove = new ArrayList<>();
for(ConnectorImplementation implementation : connectorImplList){ for (ConnectorImplementation implementation : connectorImplList) {
if(implementation != null){ if (implementation != null) {
if(!implementation.getDefinitionId().equals(definitionId) || !implementation.getDefinitionVersion().equals(definitionVersion)){ if (!implementation.getDefinitionId().equals(definitionId)
toRemove.add(implementation) ; || !implementation.getDefinitionVersion().equals(definitionVersion)) {
toRemove.add(implementation);
} }
} }
} }
connectorImplList.removeAll(toRemove) ; connectorImplList.removeAll(toRemove);
} }
return connectorImplList.toArray(new ConnectorImplementation[connectorImplList.size()]); return connectorImplList.toArray(new ConnectorImplementation[connectorImplList.size()]);
} }
......
...@@ -335,6 +335,70 @@ ...@@ -335,6 +335,70 @@
</and> </and>
</activeWhen> </activeWhen>
</handler> </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>
<extension <extension
point="org.eclipse.ui.commandImages"> 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 @@ ...@@ -2,28 +2,26 @@
/** /**
* Copyright (C) 2009 BonitaSoft S.A. * Copyright (C) 2009 BonitaSoft S.A.
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble * BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
*
* This program is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version. * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * 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. * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License * 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; package org.bonitasoft.studio.connectors.ui.wizard;
import java.io.File; 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.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager; 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.definition.IDefinitionRepositoryStore;
import org.bonitasoft.studio.connector.model.implementation.ConnectorImplementation; import org.bonitasoft.studio.connector.model.implementation.ConnectorImplementation;
import org.bonitasoft.studio.connector.model.implementation.provider.ConnectorImplementationContentProvider; import org.bonitasoft.studio.connector.model.implementation.provider.ConnectorImplementationContentProvider;
...@@ -38,40 +36,64 @@ import org.bonitasoft.studio.pics.Pics; ...@@ -38,40 +36,64 @@ import org.bonitasoft.studio.pics.Pics;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
/** /**
* @author Mickael Istria * @author Mickael Istria
*
*/ */
public class ExportConnectorWizard extends Wizard { public class ExportConnectorWizard extends Wizard {
private ExportConnectorWizardPage exportConnectorWizardPage; private ExportConnectorWizardPage exportConnectorWizardPage;
protected Optional<ConnectorImplementation> connectorImplToExport = Optional.empty();
protected Optional<ConnectorDefinition> connectorDefToExport = Optional.empty();
public ExportConnectorWizard(){ public ExportConnectorWizard() {
setDefaultPageImageDescriptor(Pics.getWizban()) ; setDefaultPageImageDescriptor(Pics.getWizban());
setWindowTitle(Messages.exportConnectorTitle); 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 @Override
public void addPages() { public void addPages() {
exportConnectorWizardPage = new ExportConnectorWizardPage(getPageTitle(),getPageDescription(),getContentProvider(),getLabelProvider(),getDefRepositoryStore()); exportConnectorWizardPage = new ExportConnectorWizardPage(getPageTitle(), getPageDescription(), getContentProvider(),
getLabelProvider(), getDefRepositoryStore());
addPage(exportConnectorWizardPage); addPage(exportConnectorWizardPage);
} }
protected LabelProvider getLabelProvider() { 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" }) @SuppressWarnings({ "rawtypes", "unchecked" })
protected IContentProvider getContentProvider() { protected IContentProvider getContentProvider() {
ConnectorImplRepositoryStore repositoryStore = RepositoryManager.getInstance().getRepositoryStore(ConnectorImplRepositoryStore.class); if (connectorImplToExport.isPresent()) {
return new ConnectorImplementationContentProvider((AbstractRepositoryStore)repositoryStore,false); 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() { protected String getPageDescription() {
...@@ -81,62 +103,60 @@ public class ExportConnectorWizard extends Wizard { ...@@ -81,62 +103,60 @@ public class ExportConnectorWizard extends Wizard {
protected String getPageTitle() { protected String getPageTitle() {
return Messages.selectConnectorImplementationToExportTitle; return Messages.selectConnectorImplementationToExportTitle;
} }
protected IDefinitionRepositoryStore getDefRepositoryStore(){ protected IDefinitionRepositoryStore getDefRepositoryStore() {
return (IDefinitionRepositoryStore)RepositoryManager.getInstance().getRepositoryStore(ConnectorDefRepositoryStore.class); return RepositoryManager.getInstance().getRepositoryStore(ConnectorDefRepositoryStore.class);
} }
/* (non-Javadoc) /*
* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#performFinish() * @see org.eclipse.jface.wizard.Wizard#performFinish()
*/ */
@Override @Override
public boolean performFinish() { public boolean performFinish() {
try { try {
getContainer().run(true, false, new IRunnableWithProgress() { getContainer().run(true, false, progressMonitor -> {
progressMonitor.beginTask(Messages.exporting, IProgressMonitor.UNKNOWN);
@Override String destPathFile = exportConnectorWizardPage.getDestFilePath();
public void run(IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException { if (destPathFile.endsWith(File.separator)) {
progressMonitor.beginTask(Messages.exporting, IProgressMonitor.UNKNOWN) ; destPathFile = destPathFile + exportConnectorWizardPage.getDestFileName();
String destPathFile=exportConnectorWizardPage.getDestFilePath(); } else {
if (destPathFile.endsWith(File.separator)){ destPathFile = destPathFile + File.separator + exportConnectorWizardPage.getDestFileName();
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) ;
}