Commit 65a055a6 authored by Romain Bioteau's avatar Romain Bioteau

BS-12182

Add menu entry opening browser
refactor open browser operation
parent d745f565
......@@ -490,4 +490,11 @@
version="0.0.0"
unpack="false"/>
<plugin
id="org.bonitasoft.studio.browser"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="src-test/java"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.bonitasoft.studio.browser</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Browser Support Plugin
Bundle-SymbolicName: org.bonitasoft.studio.browser
Bundle-Version: 6.5.0.qualifier
Bundle-Activator: org.bonitasoft.studio.browser.BrowserSupportPlugin
Bundle-Vendor: Bonitasoft S.A.
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.junit;bundle-version="4.11.0";resolution:=optional,
org.mockito;bundle-version="1.9.5";resolution:=optional,
assertj-core;bundle-version="1.5.0";resolution:=optional,
org.eclipse.ui.browser,
org.bonitasoft.studio.preferences,
org.bonitasoft.studio.common
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.browser.operation
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
src.excludes = src-test/java/
noBrowserFoundTitle=No web browser defined
noBrowserFoundMsg=The Portal cannot be launched because no web browser has been defined. Please set a web browser in order to continue.
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.bonitasoft.studio.bundles</groupId>
<artifactId>plugins</artifactId>
<version>6.5.0-SNAPSHOT</version>
</parent>
<groupId>org.bonitasoft.studio.bundles.plugins</groupId>
<artifactId>org.bonitasoft.studio.browser</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
/**
* Copyright (C) 2014 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.browser.operation;
import org.junit.After;
import org.junit.Before;
/**
* @author Romain Bioteau
*
*/
public class OpenBrowserOperationTest {
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
}
package org.bonitasoft.studio.browser;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class BrowserSupportPlugin extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.bonitasoft.studio.browser"; //$NON-NLS-1$
// The shared instance
private static BrowserSupportPlugin plugin;
/**
* The constructor
*/
public BrowserSupportPlugin() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static BrowserSupportPlugin getDefault() {
return plugin;
}
}
/**
* Copyright (C) 2014 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.browser.i18n;
import org.eclipse.osgi.util.NLS;
/**
* @author Romain Bioteau
*
*/
public class Messages extends NLS {
static {
NLS.initializeMessages("messages", Messages.class);
}
public static String noBrowserFoundTitle;
public static String noBrowserFoundMsg;
}
/**
* Copyright (C) 2014 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.browser.operation;
import java.net.URL;
import org.bonitasoft.studio.browser.i18n.Messages;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.preferences.dialog.BonitaPreferenceDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.internal.browser.ExternalBrowserInstance;
import org.eclipse.ui.internal.browser.WebBrowserUtil;
/**
* @author Romain Bioteau
*
*/
public class OpenBrowserOperation implements Runnable {
protected static final String TYPE_ID = "org.bonitasoft.studio.browser"; //$NON-NLS-1$
private final URL url;
private ExternalBrowserInstance externalBrowser;
public OpenBrowserOperation(final URL url) {
this.url = url;
}
public void setExternalBrowser(final ExternalBrowserInstance externalBrowser) {
this.externalBrowser = externalBrowser;
}
public void execute() {
Display.getDefault().syncExec(this);
}
protected void openBrowser() throws PartInitException {
if (browserIsSet()) {
IWebBrowser browser = externalBrowser;
if (browser == null) {
browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser(IWorkbenchBrowserSupport.AS_EDITOR, TYPE_ID, "", ""); //$NON-NLS-1$
}
browser.openURL(url);
}
}
protected boolean browserIsSet() {
if (noExternalBrowserSet()) {
if (MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.noBrowserFoundTitle, Messages.noBrowserFoundMsg)) {
final BonitaPreferenceDialog dialog = new BonitaPreferenceDialog(Display.getDefault().getActiveShell());
dialog.create();
dialog.setSelectedPreferencePage(BonitaPreferenceDialog.WEB_BROWSER_PAGE_ID);
dialog.open();
}
return false;
}
return true;
}
protected boolean noExternalBrowserSet() {
return !WebBrowserUtil.canUseSystemBrowser() && WebBrowserUtil.getExternalBrowserPaths().isEmpty();
}
@Override
public void run() {
try {
openBrowser();
} catch (final PartInitException e) {
BonitaStudioLog.error(e);
}
}
}
......@@ -38,7 +38,8 @@ Require-Bundle: org.bonitasoft.studio.engine;bundle-version="1.0.0",
org.bonitasoft.studio.refactoring;bundle-version="6.3.0",
org.eclipse.emf;bundle-version="2.6.0",
org.eclipse.emf.transaction,
org.eclipse.emf.databinding
org.eclipse.emf.databinding,
org.bonitasoft.studio.browser;bundle-version="6.5.0"
Export-Package: org.bonitasoft.studio.businessobject.core.operation,or
g.bonitasoft.studio.businessobject.core.repository,org.bonitasoft.stu
dio.businessobject.ui,org.bonitasoft.studio.businessobject.ui.wizard
......
......@@ -5,12 +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
* 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/>.
*/
......@@ -25,16 +25,15 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bonitasoft.studio.browser.operation.OpenBrowserOperation;
import org.bonitasoft.studio.businessobject.i18n.Messages;
import org.bonitasoft.studio.businessobject.ui.wizard.editingsupport.QueryParameterNameEditingSupport;
import org.bonitasoft.studio.businessobject.ui.wizard.editingsupport.QueryParameterTypeEditingSupport;
import org.bonitasoft.studio.common.NamingUtils;
import org.bonitasoft.studio.common.jface.BonitaStudioFontRegistry;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.engine.command.OpenBrowserCommand;
import org.bonitasoft.studio.pics.Pics;
import org.bonitasoft.studio.pics.PicsConstants;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
......@@ -84,7 +83,7 @@ import com.bonitasoft.engine.bdm.model.field.SimpleField;
/**
* @author Romain Bioteau
*
*
*/
public class QueryWizardPage extends WizardPage {
......@@ -107,33 +106,33 @@ public class QueryWizardPage extends WizardPage {
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
DataBindingContext ctx = new DataBindingContext();
public void createControl(final Composite parent) {
final DataBindingContext ctx = new DataBindingContext();
Composite composite = new Composite(parent, SWT.NONE);
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(10, 10).create());
composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
Link queryLabel = new Link(composite, SWT.NO_FOCUS);
final Link queryLabel = new Link(composite, SWT.NO_FOCUS);
queryLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).create());
queryLabel.setText(Messages.queryLink);
queryLabel.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
public void widgetSelected(final SelectionEvent e) {
performHelp();
}
});
StyledText queryText = createQueryText(composite);
final StyledText queryText = createQueryText(composite);
queryText.setFont(getMonospaceFont());
queryText.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(300, 120).create());
if (query.getContent() == null || query.getContent().isEmpty()) {
String queryExample = createQueryExample(businessObject);
final String queryExample = createQueryExample(businessObject);
query.setContent(queryExample);
if (query.getQueryParameters().isEmpty()) {
for (Field f : businessObject.getFields()) {
for (final Field f : businessObject.getFields()) {
if (f instanceof SimpleField) {
query.addQueryParameter(f.getName(), ((SimpleField) f).getType().getClazz().getName());
}
......@@ -141,22 +140,22 @@ public class QueryWizardPage extends WizardPage {
}
}
UpdateValueStrategy targetStrategy = new UpdateValueStrategy();
final UpdateValueStrategy targetStrategy = new UpdateValueStrategy();
targetStrategy.setAfterGetValidator(new IValidator() {
@Override
public IStatus validate(Object value) {
public IStatus validate(final Object value) {
if (value == null || value.toString().trim().isEmpty()) {
return ValidationStatus.error(Messages.emptyQueryError);
}
return checkParametersUsage(value.toString());
}
});
UpdateValueStrategy strategy = new UpdateValueStrategy();
final UpdateValueStrategy strategy = new UpdateValueStrategy();
strategy.setAfterGetValidator(new IValidator() {
@Override
public IStatus validate(Object value) {
public IStatus validate(final Object value) {
return checkParametersUsage(value.toString());
}
});
......@@ -164,29 +163,29 @@ public class QueryWizardPage extends WizardPage {
queryBinding = ctx
.bindValue(SWTObservables.observeText(queryText, SWT.Modify), PojoObservables.observeValue(getQuery(), "content"), targetStrategy, strategy);
Label queryParamLabel = new Label(composite, SWT.NONE);
final Label queryParamLabel = new Label(composite, SWT.NONE);
queryParamLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.FILL).indent(0, 10).create());
queryParamLabel.setText(Messages.parameters);
ControlDecoration controlDecoration = new ControlDecoration(queryParamLabel, SWT.RIGHT);
final ControlDecoration controlDecoration = new ControlDecoration(queryParamLabel, SWT.RIGHT);
controlDecoration.setImage(Pics.getImage(PicsConstants.hint));
controlDecoration.setDescriptionText(Messages.jpqlParametersHint);
controlDecoration.setShowOnlyOnFocus(false);
createQueryParametersTable(composite, ctx);
Label queryResultTypeLabel = new Label(composite, SWT.NONE);
final Label queryResultTypeLabel = new Label(composite, SWT.NONE);
queryResultTypeLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).indent(0, 5).create());
queryResultTypeLabel.setText(Messages.queryResultType);
ComboViewer resultTypeViewer = createReturnTypeComboViewer(composite);
final ComboViewer resultTypeViewer = createReturnTypeComboViewer(composite);
resultTypeViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
resultTypeViewer.setContentProvider(ArrayContentProvider.getInstance());
resultTypeViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
String className = element.toString();
public String getText(final Object element) {
final String className = element.toString();
if (List.class.getName().equals(className)) {
return Messages.multipleReturnType;
} else if (Long.class.getName().equals(className)) {
......@@ -200,12 +199,12 @@ public class QueryWizardPage extends WizardPage {
}
});
resultTypeViewer.setInput(getSupportedReturnTypes(businessObject));
IViewerObservableValue returnTypeSelectionObservable = ViewersObservables.observeSingleSelection(resultTypeViewer);
final IViewerObservableValue returnTypeSelectionObservable = ViewersObservables.observeSingleSelection(resultTypeViewer);
ctx.bindValue(returnTypeSelectionObservable, PojoObservables.observeValue(getQuery(), "returnType"));
returnTypeSelectionObservable.addValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {
public void handleValueChange(final ValueChangeEvent event) {
queryBinding.validateTargetToModel();
}
});
......@@ -217,17 +216,17 @@ public class QueryWizardPage extends WizardPage {
return BonitaStudioFontRegistry.getMonospaceFont();
}
protected ComboViewer createReturnTypeComboViewer(Composite composite) {
protected ComboViewer createReturnTypeComboViewer(final Composite composite) {
return new ComboViewer(composite, SWT.BORDER | SWT.READ_ONLY);
}
protected StyledText createQueryText(Composite composite) {
protected StyledText createQueryText(final Composite composite) {
return new StyledText(composite, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
}
private String createQueryExample(BusinessObject businessObject) {
String boName = NamingUtils.getSimpleName(businessObject.getQualifiedName());
char var = Character.toLowerCase(boName.charAt(0));
private String createQueryExample(final BusinessObject businessObject) {
final String boName = NamingUtils.getSimpleName(businessObject.getQualifiedName());
final char var = Character.toLowerCase(boName.charAt(0));
StringBuilder sb = new StringBuilder();
sb.append("SELECT ");
sb.append(var);
......@@ -238,7 +237,7 @@ public class QueryWizardPage extends WizardPage {
sb.append(var);
sb.append(" \n");
sb.append("WHERE ");
for (Field f : businessObject.getFields()) {
for (final Field f : businessObject.getFields()) {
if (f instanceof SimpleField) {
if (f.isCollection() != null && f.isCollection()) {
sb.append(":");
......@@ -272,25 +271,25 @@ public class QueryWizardPage extends WizardPage {
return sb.toString();
}
private List<String> getSupportedReturnTypes(BusinessObject currentBo) {
private List<String> getSupportedReturnTypes(final BusinessObject currentBo) {
return Arrays.asList(List.class.getName(), currentBo.getQualifiedName(), Long.class.getName(), Double.class.getName(), Float.class.getName(),
Integer.class.getName());
}
protected IStatus checkParametersUsage(String queryContent) {
List<QueryParameter> parameters = getQuery().getQueryParameters();
Set<String> parametersList = new HashSet<String>();
for (QueryParameter p : parameters) {
protected IStatus checkParametersUsage(final String queryContent) {
final List<QueryParameter> parameters = getQuery().getQueryParameters();
final Set<String> parametersList = new HashSet<String>();
for (final QueryParameter p : parameters) {
parametersList.add(":" + p.getName());
if (!queryContent.contains(":" + p.getName())) {
return ValidationStatus.warning(Messages.bind(Messages.parameterNotUsedInQueryWarning, p.getName()));
}
}
Pattern pattern = Pattern.compile(":[\\w]+");
Matcher matcher = pattern.matcher(queryContent);
<