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

feat(deploy) save last opened app (#1858)

Closes BST-481
parent 8fd5d91a
......@@ -73,6 +73,7 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.progress.IProgressService;
import org.eclipse.ui.statushandlers.StatusManager;
......@@ -236,7 +237,7 @@ public class DeployArtifactsHandler {
BOSEngineManager.getInstance().getApplicationAPI(session),
BOSEngineManager.getInstance().getProfileAPI(session),
BOSEngineManager.getInstance().getIdentityAPI(session));
if (IDialogConstants.OPEN_ID == DeploySuccessDialog.open(activeShell, contentProvider)) {
if (IDialogConstants.OPEN_ID == DeploySuccessDialog.open(activeShell, contentProvider, WorkbenchPlugin.getDefault().getDialogSettings())) {
try {
new OpenBrowserOperation(contentProvider.getSelectedURL()).execute();
} catch (MalformedURLException | UnsupportedEncodingException | URISyntaxException e) {
......
......@@ -14,12 +14,16 @@
*/
package org.bonitasoft.studio.application.ui.control;
import java.util.Arrays;
import org.bonitasoft.studio.application.i18n.Messages;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.core.ActiveOrganizationProvider;
import org.bonitasoft.studio.ui.widget.ComboWidget;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
......@@ -31,26 +35,30 @@ import org.eclipse.swt.widgets.Shell;
public class DeploySuccessDialog extends MessageDialog {
private static final String DEFAULT_APP_SELECTION = "DEFAULT_APP_SELECTION";
public static int open(Shell parentShell, DeployedAppContentProvider contentProvider) {
public static int open(Shell parentShell, DeployedAppContentProvider contentProvider,
IDialogSettings dialogSettings) {
return new DeploySuccessDialog(parentShell, Messages.deployStatus, Messages.deploySuccessMsg,
MessageDialog.INFORMATION, contentProvider).open();
MessageDialog.INFORMATION, contentProvider, dialogSettings).open();
}
private DeployedAppContentProvider contentProvider;
private DataBindingContext ctx;
private IDialogSettings dialogSettings;
public DeploySuccessDialog(Shell parentShell, String dialogTitle, String dialogMessage, int dialogImageType,
DeployedAppContentProvider contentProvider) {
DeployedAppContentProvider contentProvider, IDialogSettings dialogSettings) {
super(parentShell, dialogTitle, null, dialogMessage, dialogImageType, 1,
new String[] { IDialogConstants.CLOSE_LABEL, IDialogConstants.OPEN_LABEL });
this.contentProvider = contentProvider;
this.dialogSettings = dialogSettings;
}
@Override
protected Control createCustomArea(Composite parent) {
ctx = new DataBindingContext();
Composite container = new Composite(parent, SWT.NONE);
container.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
container.setLayout(GridLayoutFactory.fillDefaults().create());
......@@ -58,13 +66,16 @@ public class DeploySuccessDialog extends MessageDialog {
new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL)
.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
contentProvider.setSelection(defaultSelection(dialogSettings));
new ComboWidget.Builder()
.withLabel(Messages.youCanOpenApp)
.labelAbove()
.fill()
.grabHorizontalSpace()
.readOnly()
.withMessage(String.format("%s : %s", org.bonitasoft.studio.actors.i18n.Messages.defaultUser, new ActiveOrganizationProvider().getDefaultUser()))
.withMessage(String.format("%s : %s", org.bonitasoft.studio.actors.i18n.Messages.defaultUser,
new ActiveOrganizationProvider().getDefaultUser()))
.withItems(contentProvider.getItems())
.bindTo(PojoProperties.value("selection").observe(contentProvider))
.inContext(ctx)
......@@ -72,13 +83,33 @@ public class DeploySuccessDialog extends MessageDialog {
return container;
}
private String defaultSelection(IDialogSettings dialogSettings) {
IDialogSettings section = dialogSettings
.getSection(RepositoryManager.getInstance().getCurrentRepository().getName());
if (section != null && section.get(DEFAULT_APP_SELECTION) != null) {
String lastSelection = section.get(DEFAULT_APP_SELECTION);
return Arrays.asList(contentProvider.getItems()).contains(lastSelection) ? lastSelection
: contentProvider.getSelection();
}
return contentProvider.getSelection();
}
private void saveSelectedApp(IDialogSettings dialogSettings) {
String sectionName = RepositoryManager.getInstance().getCurrentRepository().getName();
IDialogSettings section = dialogSettings.getSection(sectionName);
if (section == null) {
section = dialogSettings.addNewSection(sectionName);
}
section.put(DEFAULT_APP_SELECTION, contentProvider.getSelection());
}
@Override
public boolean close() {
ctx.dispose();
return super.close();
}
@Override
protected void buttonPressed(int buttonId) {
super.buttonPressed(buttonId);
......@@ -87,6 +118,7 @@ public class DeploySuccessDialog extends MessageDialog {
setReturnCode(IDialogConstants.CLOSE_ID);
break;
default:
saveSelectedApp(dialogSettings);
setReturnCode(IDialogConstants.OPEN_ID);
break;
}
......
......@@ -137,7 +137,10 @@ public class SelectArtifactToDeployPage implements ControlSupplier {
@Override
public void saveSettings(IDialogSettings settings) {
mergeSets();
IDialogSettings section = settings.addNewSection(repositoryModel.getName());
IDialogSettings section = settings.getSection(repositoryModel.getName());
if(section == null) {
section = settings.addNewSection(repositoryModel.getName());
}
section.put(DEPLOY_DEFAULT_SELECTION, stringify(allCheckedElements));
section.put(CLEAN_BDM_DEFAULT_SELECTION, cleanBDM);
section.put(VALIDATE_DEFAULT_SELECTION, validate);
......
......@@ -14,19 +14,14 @@
*/
package org.bonitasoft.studio.ui.wizard;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import java.util.function.Supplier;
import org.bonitasoft.studio.ui.databinding.NoMessageWizardPageSupport;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
public class WizardPageBuilder {
......
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