Commit 91fb45bc authored by Romain Bioteau's avatar Romain Bioteau

fix(Connector) Improve generic wizard

* Add outputs description support
* Add rest connector
parent e8208f6b
......@@ -20,25 +20,11 @@ import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.bonitasoft.studio.common.repository.store.SourceRepositoryStore;
import org.bonitasoft.studio.connectors.repository.ImportConnectorArchiveOperation;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
/**
* @author Romain Bioteau
*
*/
public class ImportActorFilterArchiveOperation extends ImportConnectorArchiveOperation{
public class ImportActorFilterArchiveOperation extends ImportConnectorArchiveOperation{
@Override
protected IStatus checkTypeIsValid(String type) {
if(!ExportActorFilterArchiveOperation.FILTER_TYPE.equals(type)){
return ValidationStatus.error("This is not a filter archive") ;
}
return Status.OK_STATUS;
}
@Override
protected IRepositoryStore<?> getImplementationStore() {
......
......@@ -83,6 +83,8 @@ public class DefinitionResourceProvider {
public static final String connectorDefinitionDescription = "connectorDefinitionDescription";
public static final String fieldDescription = "description";
private static final String CLASSPATH_DIR = "dependencies";
private static final String OUTPUTS_DESC = "outputsDescription";
private static final String OUTPUT_DESC = "output.description";
private ImageRegistry categoryImageRegistry;
private final ImageRegistry definitionImageRegistry;
......@@ -95,6 +97,7 @@ public class DefinitionResourceProvider {
private final Map<String, ResourceBundle> resourceBundleCache = new WeakHashMap<>();
private final static Map<IRepositoryStore<? extends IRepositoryFileStore>, DefinitionResourceProvider> INSTANCES_MAP;
static {
INSTANCES_MAP = new WeakHashMap<>();
}
......@@ -233,6 +236,14 @@ public class DefinitionResourceProvider {
return getMessage(definition, fieldId + "." + fieldDescription);
}
public String getOutputsDescription(final ConnectorDefinition definition) {
return getMessage(definition, OUTPUTS_DESC);
}
public String getOutputDescription(final ConnectorDefinition definition, final String outputName) {
return getMessage(definition, outputName + "." + OUTPUT_DESC);
}
public String getCategoryLabel(final ConnectorDefinition definition,
final String categoryId) {
String label = getMessage(definition, categoryId + "." + category);
......@@ -390,6 +401,10 @@ public class DefinitionResourceProvider {
return messages.getProperty(pageId + "." + pageDescription);
}
public String getOutputsDescription(final Properties messages) {
return messages.getProperty(OUTPUTS_DESC);
}
public String getCategoryLabel(final Properties messages, final Category category) {
String label = messages.getProperty(category.getId() + "."
+ DefinitionResourceProvider.category);
......@@ -774,4 +789,5 @@ public class DefinitionResourceProvider {
messages.remove(c.getId() + "." + category);
}
}
......@@ -23,7 +23,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import org.bonitasoft.studio.common.NamingUtils;
import org.bonitasoft.studio.common.ProjectUtil;
......@@ -118,12 +117,6 @@ public class ImportConnectorArchiveOperation implements IRunnableWithProgress {
BonitaStudioLog.error(e);
}
status = readManifest(tmp);
if (status.getSeverity() != IStatus.OK) {
PlatformUtil.delete(tmp, monitor);
return;
}
try {
FileActionDialog.activateYesNoToAll();
importConnectorDefinition(tmp);
......@@ -138,45 +131,6 @@ public class ImportConnectorArchiveOperation implements IRunnableWithProgress {
return status;
}
private IStatus readManifest(final File tmp) {
final File manifest = new File(tmp, ExportConnectorArchiveOperation.DESCRIPTOR_FILE);
if (!manifest.exists()) {
return ValidationStatus.error("Descriptor file not found");
}
try {
final Properties p = new Properties();
final FileInputStream fis = new FileInputStream(manifest);
p.load(fis);
final String version = p.getProperty(ExportConnectorArchiveOperation.VERSION);
if (version == null || version.isEmpty()) {
return ValidationStatus.error("Version is missing in the descriptor");
}
final String type = p.getProperty(ExportConnectorArchiveOperation.TYPE);
if (type == null || type.isEmpty()) {
return ValidationStatus.error("Type is missing in the descriptor");
}
final IStatus status = checkTypeIsValid(type);
if (status.getSeverity() != IStatus.OK) {
return status;
}
} catch (final Exception e) {
return ValidationStatus.error("Cannot read the descriptor file");
}
return Status.OK_STATUS;
}
protected IStatus checkTypeIsValid(final String type) {
if (!ExportConnectorArchiveOperation.CONNECTOR_TYPE.equals(type)) {
return ValidationStatus.error("This is not a connector archive");
}
return Status.OK_STATUS;
}
private void importConnectorImplementation(final File tmpDir) {
final File[] files = tmpDir.listFiles(implFileFilter);
if (files != null) {
......@@ -315,7 +269,7 @@ public class ImportConnectorArchiveOperation implements IRunnableWithProgress {
private void importImplementationSources(final File tmpDir, final String implJarName) {
final File srcDir = new File(tmpDir, ExportConnectorArchiveOperation.SRC_DIR);
if (srcDir.exists()) {
final List<File> files = new ArrayList<File>();
final List<File> files = new ArrayList<>();
findSourceFiles(srcDir, files);
final SourceRepositoryStore sourceStore = getSourceStore();
for (final File sourceFile : files) {
......
......@@ -160,7 +160,7 @@ public class ConnectorWizard extends ExtensibleWizard implements
connectorWorkingCopy.setConfiguration(configuration);
editMode = false;
this.connectorContainmentFeature = connectorContainmentFeature;
this.featureToCheckForUniqueID = new HashSet<EStructuralFeature>();
this.featureToCheckForUniqueID = new HashSet<>();
this.featureToCheckForUniqueID.add(connectorContainmentFeature);
setWindowTitle(Messages.connectors);
setNeedsProgressMonitor(false);
......@@ -209,7 +209,7 @@ public class ConnectorWizard extends ExtensibleWizard implements
initializeContainment();
contributions = new ArrayList<CustomWizardExtension>();
contributions = new ArrayList<>();
for (final IConfigurationElement element : BonitaStudioExtensionRegistryManager
.getInstance().getConfigurationElements(CUSTOM_WIZARD_ID)) {
contributions.add(new CustomWizardExtension(element));
......@@ -311,11 +311,11 @@ public class ConnectorWizard extends ExtensibleWizard implements
boolean changed = false;
if (configuration != null) {
final EList<Input> inputs = definition.getInput();
final Set<String> inputNames = new HashSet<String>();
final Set<String> inputNames = new HashSet<>();
for (final Input in : inputs) {
inputNames.add(in.getName());
}
final Set<String> connectorParamKey = new HashSet<String>();
final Set<String> connectorParamKey = new HashSet<>();
for (final ConnectorParameter parameter : configuration
.getParameters()) {
connectorParamKey.add(parameter.getKey());
......@@ -323,7 +323,7 @@ public class ConnectorWizard extends ExtensibleWizard implements
if (!inputNames.equals(connectorParamKey)) {
connectorParamKey.removeAll(inputNames);
final List<ConnectorParameter> toRemove = new ArrayList<ConnectorParameter>();
final List<ConnectorParameter> toRemove = new ArrayList<>();
for (final ConnectorParameter parameter : configuration
.getParameters()) {
if (connectorParamKey.contains(parameter.getKey())) {
......@@ -336,7 +336,7 @@ public class ConnectorWizard extends ExtensibleWizard implements
}
}
final EList<Output> outputs = definition.getOutput();
final Set<String> outputNames = new HashSet<String>();
final Set<String> outputNames = new HashSet<>();
for (final Output out : outputs) {
outputNames.add(out.getName());
}
......@@ -416,6 +416,7 @@ public class ConnectorWizard extends ExtensibleWizard implements
}
}
outputPage.setMessageProvider(messageProvider);
outputPage.setElementContainer(container);
outputPage.setConnector(connectorWorkingCopy);
outputPage.setDefinition(definition);
......@@ -617,7 +618,7 @@ public class ConnectorWizard extends ExtensibleWizard implements
}
protected List<IWizardPage> getPagesFor(final ConnectorDefinition definition) {
final List<IWizardPage> result = new ArrayList<IWizardPage>();
final List<IWizardPage> result = new ArrayList<>();
if (isDatabaseConnector(definition)) {// DRIVER SELECTION PAGE
result.add(new DatabaseConnectorDriversWizardPage(definition
......
......@@ -19,6 +19,7 @@ package org.bonitasoft.studio.connectors.ui.wizard.page;
import org.bonitasoft.studio.common.IBonitaVariableContext;
import org.bonitasoft.studio.connector.model.definition.ConnectorDefinition;
import org.bonitasoft.studio.connector.model.i18n.DefinitionResourceProvider;
import org.bonitasoft.studio.connectors.i18n.Messages;
import org.bonitasoft.studio.expression.editor.provider.IExpressionNatureProvider;
import org.bonitasoft.studio.model.process.Connector;
......@@ -45,6 +46,7 @@ public abstract class AbstractConnectorOutputWizardPage extends WizardPage imple
private IWizardPage previousPageBackup;
private boolean isPageFlowContext = false;
private IExpressionNatureProvider storageExpressionProvider;
private DefinitionResourceProvider messageProvider;
public AbstractConnectorOutputWizardPage(){
......@@ -99,13 +101,17 @@ public abstract class AbstractConnectorOutputWizardPage extends WizardPage imple
this.elementContainer = elementContainer;
}
public DefinitionResourceProvider getMessageProvider() {
return messageProvider;
}
@Override
public IWizardPage getPreviousPage() {
if(previousPageBackup != null){
return previousPageBackup;
}
IWizard wizard = getWizard();
final IWizard wizard = getWizard();
if(wizard != null){
return wizard.getPreviousPage(this);
}
......@@ -127,7 +133,6 @@ public abstract class AbstractConnectorOutputWizardPage extends WizardPage imple
@Override
public void setIsPageFlowContext(boolean isPageFlowContext) {
this.isPageFlowContext=isPageFlowContext;
}
public IExpressionNatureProvider getStorageExpressionProvider() {
......@@ -138,4 +143,8 @@ public abstract class AbstractConnectorOutputWizardPage extends WizardPage imple
IExpressionNatureProvider storageExpressionProvider) {
this.storageExpressionProvider = storageExpressionProvider;
}
public void setMessageProvider(DefinitionResourceProvider messageProvider) {
this.messageProvider = messageProvider;
}
}
/**
* Copyright (C) 2009 BonitaSoft S.A.
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
<<<<<<< HEAD
*
=======
>>>>>>> refs/remotes/origin/master
* 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.
<<<<<<< HEAD
*
=======
>>>>>>> refs/remotes/origin/master
* 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.
<<<<<<< HEAD
*
=======
>>>>>>> refs/remotes/origin/master
* 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.ui.wizard.page;
import java.net.MalformedURLException;
import java.net.URL;
import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.connector.model.i18n.DefinitionResourceProvider;
import org.bonitasoft.studio.expression.editor.filter.AvailableExpressionTypeFilter;
import org.bonitasoft.studio.expression.editor.operation.OperationsComposite;
import org.bonitasoft.studio.expression.editor.operation.WizardPageOperationsComposite;
......@@ -36,8 +25,16 @@ import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import com.google.common.base.Strings;
/**
* @author Romain Bioteau
......@@ -45,11 +42,15 @@ import org.eclipse.swt.widgets.Control;
*/
public class ConnectorOutputWizardPage extends AbstractConnectorOutputWizardPage {
protected static final String HELP_BROWSER_ID = "org.bonitasoft.studio.help.browser";
private OperationsComposite lineComposite;
private ScrolledComposite scrolledComposite;
@Override
protected Control doCreateControl(final Composite parent, final EMFDataBindingContext context) {
final DefinitionResourceProvider messageProvider = getMessageProvider();
final String outputsDescription = messageProvider.getOutputsDescription(getDefinition());
scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL);
scrolledComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create());
scrolledComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
......@@ -62,6 +63,31 @@ public class ConnectorOutputWizardPage extends AbstractConnectorOutputWizardPage
final Composite mainComposite = new Composite(scrolledComposite, SWT.NONE);
mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).create());
if (!Strings.isNullOrEmpty(outputsDescription)) {
final Link description = new Link(mainComposite, SWT.WRAP);
description.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
description.setText(outputsDescription);
description.addSelectionListener(new SelectionAdapter() {
/*
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
IWebBrowser browser;
try {
browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser(HELP_BROWSER_ID);
browser.openURL(new URL(e.text));
} catch (final PartInitException | MalformedURLException e1) {
BonitaStudioLog.error(e1);
}
}
});
}
lineComposite = new WizardPageOperationsComposite(null, mainComposite, rightFilter, leftFilter, isPageFlowContext());
lineComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 280).create());
final IExpressionNatureProvider storageExpressionProvider = getStorageExpressionProvider();
......
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