Commit 05ac3958 authored by Adrien's avatar Adrien Committed by Romain Bioteau
Browse files

feat(la) export file name (#433)

* possibility to choose the name of exported file

closes [BS-16534](https://bonitasoft.atlassian.net/browse/BS-16534)
parent 2af33375
......@@ -26,12 +26,13 @@ url=URL
export=Export
exportApplicationDescriptor= Export an application file
exportDoneTitle=Export done
exportDoneMessage=Export operation finished successfully
exportDoneMessage=Application file has been exported successfully to '%s'.
importApplicationDescriptorLabel=Select an application file
importApplicationDescriptor=Import application file
browse=Browse...
filePathNotEmpty=You must select an application descriptor to import
fileDoesntExist=This file doesn't exist
failToDeleteFile=An error occurred while deleting file.
importConflictWarning=An application file with the same name already exists
importLabel=Import
notAnApplicationError=Invalid application file
......
......@@ -22,10 +22,11 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.la.repository.ApplicationFileStore;
import org.bonitasoft.studio.la.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.la.ui.control.SelectApplicationDescriptorPage;
import org.bonitasoft.studio.la.ui.control.SelectMultiApplicationDescriptorPage;
import org.bonitasoft.studio.ui.wizard.WizardBuilder;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
......@@ -47,9 +48,9 @@ public class DeleteApplicationHandler {
});
}
private WizardBuilder<Stream<ApplicationFileStore>> createWizard(WizardBuilder<Stream<ApplicationFileStore>> builder,
private WizardBuilder<Stream<IRepositoryFileStore>> createWizard(WizardBuilder<Stream<IRepositoryFileStore>> builder,
RepositoryAccessor repositoryAccessor, Shell activeShell) {
SelectApplicationDescriptorPage selectApplicationDescriptorPage = new SelectApplicationDescriptorPage(
SelectApplicationDescriptorPage selectApplicationDescriptorPage = new SelectMultiApplicationDescriptorPage(
repositoryAccessor);
return builder.withTitle(Messages.deleteExistingApplication)
.havingPage(newPage()
......@@ -59,7 +60,7 @@ public class DeleteApplicationHandler {
.onFinish(container -> deleteFinish(selectApplicationDescriptorPage, activeShell));
}
private Optional<Stream<ApplicationFileStore>> deleteFinish(
private Optional<Stream<IRepositoryFileStore>> deleteFinish(
SelectApplicationDescriptorPage selectApplicationDescriptorPage, Shell activeShell) {
return MessageDialog.openConfirm(activeShell, Messages.deleteConfirmation,
String.format(Messages.deleteConfirmationMessage, getListAppToDelete(selectApplicationDescriptorPage)))
......
/*******************************************************************************
* Copyright (C) 2017 BonitaSoft S.A.
* BonitaSoft is a trademark of BonitaSoft SA.
* This software file is BONITASOFT CONFIDENTIAL. Not For Distribution.
* For commercial licensing information, contact:
* BonitaSoft, 32 rue Gustave Eiffel 38000 Grenoble
* or BonitaSoft US, 51 Federal Street, Suite 305, San Francisco, CA 94107
*******************************************************************************/
package org.bonitasoft.studio.la.handler;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Optional;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.jface.MessageDialogWithPrompt;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.la.LivingApplicationPlugin;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.ui.dialog.ExceptionDialogHandler;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
public class ExportApplicationFileAction {
public static final String DO_NOT_SHOW_EXPORT_MESSAGE_DIALOG = "DO_NOT_SHOW_EXPORT_MESSAGE_DIALOG";
public Optional<IRepositoryFileStore> export(Shell shell, IRepositoryFileStore fileStore) {
final Optional<String> optionalPath = getPath(shell, fileStore);
if (optionalPath.isPresent()) {
File targetFile = Paths.get(optionalPath.get()).toFile();
if (targetFile.exists() && !FileActionDialog.overwriteQuestion(targetFile.getName())) {
return Optional.empty();
}
final IPreferenceStore preferenceStore = LivingApplicationPlugin.getDefault().getPreferenceStore();
if (!preferenceStore.getBoolean(DO_NOT_SHOW_EXPORT_MESSAGE_DIALOG)) {
MessageDialogWithPrompt.open(MessageDialog.WARNING,
shell,
Messages.exportApplicationDescriptorTitle,
Messages.exportApplicationDescriptorMessage,
Messages.doNotShowMeAgain,
false,
preferenceStore,
DO_NOT_SHOW_EXPORT_MESSAGE_DIALOG,
SWT.NONE);
}
try {
Files.copy(fileStore.getResource().getLocation().toFile().toPath(), targetFile.toPath(),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
new ExceptionDialogHandler().openErrorDialog(Display.getCurrent().getActiveShell(),
Messages.exportFailedTitle, e);
}
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.exportDoneTitle,
String.format(Messages.exportDoneMessage, targetFile.getAbsolutePath()));
return Optional.of(fileStore);
}
return Optional.empty();
}
protected Optional<String> getPath(Shell shell, IRepositoryFileStore fStore) {
final FileDialog fd = new FileDialog(shell, SWT.SAVE | SWT.SHEET);
fd.setFileName(fStore.getName());
fd.setFilterExtensions(new String[] { "*.xml" });
fd.setText(Messages.exportApplicationDescriptor);
return Optional.ofNullable(fd.open());
}
}
......@@ -17,93 +17,36 @@ package org.bonitasoft.studio.la.handler;
import static org.bonitasoft.studio.ui.wizard.WizardBuilder.newWizard;
import static org.bonitasoft.studio.ui.wizard.WizardPageBuilder.newPage;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.bonitasoft.studio.common.jface.MessageDialogWithPrompt;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.ui.OverwriteFileFilter;
import org.bonitasoft.studio.la.LivingApplicationPlugin;
import org.bonitasoft.studio.la.core.ExportApplicationRunnable;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.la.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.la.ui.control.SelectApplicationDescriptorPage;
import org.bonitasoft.studio.ui.dialog.ExceptionDialogHandler;
import org.bonitasoft.studio.la.ui.control.SelectSingleApplicationDescriptorPage;
import org.bonitasoft.studio.ui.wizard.WizardBuilder;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ExportApplicationHandler {
public static final String DO_NOT_SHOW_EXPORT_MESSAGE_DIALOG = "DO_NOT_SHOW_EXPORT_MESSAGE_DIALOG";
@Execute
public void exportApplicationWizard(Shell activeShell, RepositoryAccessor repositoryAccessor) {
createWizard(newWizard(), repositoryAccessor)
createWizard(newWizard(), repositoryAccessor, activeShell)
.open(activeShell, Messages.export);
}
private WizardBuilder<List<IRepositoryFileStore>> createWizard(WizardBuilder<List<IRepositoryFileStore>> builder,
RepositoryAccessor repositoryAccessor) {
final SelectApplicationDescriptorPage exportApplicationDescriptorPage = new SelectApplicationDescriptorPage(
private WizardBuilder<IRepositoryFileStore> createWizard(WizardBuilder<IRepositoryFileStore> builder,
RepositoryAccessor repositoryAccessor, Shell activeShell) {
final SelectSingleApplicationDescriptorPage exportApplicationDescriptorPage = new SelectSingleApplicationDescriptorPage(
repositoryAccessor);
ExportApplicationFileAction exportApplicationFileAction = new ExportApplicationFileAction();
return builder.withTitle(Messages.exportApplicationDescriptor)
.havingPage(newPage()
.withTitle(Messages.exportApplicationDescriptor)
.withDescription(Messages.exportApplicationDescriptor)
.withControl(exportApplicationDescriptorPage))
.onFinish(container -> finish(exportApplicationDescriptorPage, container));
}
private Optional<List<IRepositoryFileStore>> finish(SelectApplicationDescriptorPage exportApplicationDescriptorPage,
IWizardContainer container) {
final Optional<String> optionalPath = getPath(Display.getCurrent().getActiveShell());
if (optionalPath.isPresent()) {
final List<IRepositoryFileStore> resolveConflicts = new OverwriteFileFilter(optionalPath.get())
.resolveConflicts(exportApplicationDescriptorPage.getSelection().collect(Collectors.toList()));
if (resolveConflicts.isEmpty()) {
return Optional.empty();
}
final IPreferenceStore preferenceStore = LivingApplicationPlugin.getDefault().getPreferenceStore();
if (!preferenceStore.getBoolean(DO_NOT_SHOW_EXPORT_MESSAGE_DIALOG)) {
MessageDialogWithPrompt.open(MessageDialog.WARNING,
container.getShell(),
Messages.exportApplicationDescriptorTitle,
Messages.exportApplicationDescriptorMessage,
Messages.doNotShowMeAgain,
false,
preferenceStore,
DO_NOT_SHOW_EXPORT_MESSAGE_DIALOG,
SWT.NONE);
}
final ExportApplicationRunnable operation = new ExportApplicationRunnable(optionalPath.get(), resolveConflicts);
try {
container.run(true, false, operation);
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.exportDoneTitle,
String.format(Messages.exportDoneMessage));
return Optional.of(resolveConflicts);
} catch (InvocationTargetException | InterruptedException e) {
new ExceptionDialogHandler().openErrorDialog(Display.getCurrent().getActiveShell(),
Messages.exportFailedTitle, e);
}
}
return Optional.empty();
}
protected Optional<String> getPath(Shell shell) {
final DirectoryDialog fd = new DirectoryDialog(shell, SWT.SAVE | SWT.SHEET);
fd.setText(Messages.exportApplicationDescriptor);
return Optional.ofNullable(fd.open());
.onFinish(container -> exportApplicationFileAction
.export(activeShell, exportApplicationDescriptorPage.getSingleSelection()));
}
@CanExecute
......
......@@ -23,7 +23,6 @@ import java.util.stream.Stream;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.la.repository.ApplicationFileStore;
import org.bonitasoft.studio.la.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.la.ui.control.SelectRenameApplicationDescriptorPage;
import org.bonitasoft.studio.ui.wizard.WizardBuilder;
......@@ -40,7 +39,7 @@ public class OpenApplicationHandler {
.ifPresent(selection -> selection.forEach(IRepositoryFileStore::open));
}
private WizardBuilder<Stream<ApplicationFileStore>> createWizard(WizardBuilder<Stream<ApplicationFileStore>> builder,
private WizardBuilder<Stream<IRepositoryFileStore>> createWizard(WizardBuilder<Stream<IRepositoryFileStore>> builder,
RepositoryAccessor repositoryAccessor) {
SelectRenameApplicationDescriptorPage selectApplicationDescriptorPage = new SelectRenameApplicationDescriptorPage(
repositoryAccessor);
......
......@@ -74,6 +74,7 @@ public class Messages extends NLS {
public static String rename;
public static String renameFile;
public static String menuLevelWarning;
public static String failToDeleteFile;
static {
NLS.initializeMessages("messages", Messages.class);
......
......@@ -14,8 +14,8 @@
*/
package org.bonitasoft.studio.la.ui.control;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.la.repository.ApplicationFileStore;
import org.bonitasoft.studio.la.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.la.ui.validator.ApplicationDescriptorFileNameValidator;
import org.bonitasoft.studio.ui.validator.InputValidatorWrapper;
......@@ -28,7 +28,7 @@ import com.google.common.base.Objects;
public class RenameApplicationDescriptorFileDialog {
public static boolean open(Shell shell, ApplicationRepositoryStore applicationRepositoryStore,
ApplicationFileStore applicationFileStore) {
IRepositoryFileStore applicationFileStore) {
String currentFileName = applicationFileStore.getDisplayName();
final InputDialog dialog = new InputDialog(shell, Messages.rename, Messages.renameFile,
currentFileName, new InputValidatorWrapper(
......
......@@ -17,7 +17,7 @@ package org.bonitasoft.studio.la.ui.control;
import java.util.stream.Stream;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.la.repository.ApplicationFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.la.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.la.ui.providers.ApplicationLabelProvider;
import org.bonitasoft.studio.ui.wizard.ControlSupplier;
......@@ -40,7 +40,7 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
public class SelectApplicationDescriptorPage implements ControlSupplier {
public abstract class SelectApplicationDescriptorPage implements ControlSupplier {
private static final int TABLE_WIDTH_HINT = 600;
......@@ -58,7 +58,7 @@ public class SelectApplicationDescriptorPage implements ControlSupplier {
mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
mainComposite.setLayout(GridLayoutFactory.fillDefaults().create());
applicationsTableViewer = new TableViewer(mainComposite);
applicationsTableViewer = createTableViewer(mainComposite);
applicationsTableViewer.getControl().setLayoutData(
GridDataFactory.fillDefaults().grab(true, true).hint(TABLE_WIDTH_HINT, SWT.DEFAULT).create());
applicationsTableViewer.setContentProvider(ArrayContentProvider.getInstance());
......@@ -82,7 +82,9 @@ public class SelectApplicationDescriptorPage implements ControlSupplier {
return mainComposite;
}
public Stream<ApplicationFileStore> getSelection() {
protected abstract TableViewer createTableViewer(Composite mainComposite);
public Stream<IRepositoryFileStore> getSelection() {
return ((IStructuredSelection) applicationsTableViewer.getSelection()).toList().stream();
}
......
/*******************************************************************************
* Copyright (C) 2017 BonitaSoft S.A.
* BonitaSoft is a trademark of BonitaSoft SA.
* This software file is BONITASOFT CONFIDENTIAL. Not For Distribution.
* For commercial licensing information, contact:
* BonitaSoft, 32 rue Gustave Eiffel 38000 Grenoble
* or BonitaSoft US, 51 Federal Street, Suite 305, San Francisco, CA 94107
*******************************************************************************/
package org.bonitasoft.studio.la.ui.control;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Composite;
public class SelectMultiApplicationDescriptorPage extends SelectApplicationDescriptorPage {
public SelectMultiApplicationDescriptorPage(RepositoryAccessor repositoryAccessor) {
super(repositoryAccessor);
}
@Override
protected TableViewer createTableViewer(Composite mainComposite) {
return new TableViewer(mainComposite);
}
}
......@@ -28,7 +28,7 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
public class SelectRenameApplicationDescriptorPage extends SelectApplicationDescriptorPage {
public class SelectRenameApplicationDescriptorPage extends SelectMultiApplicationDescriptorPage {
Shell currentShell;
......
/*******************************************************************************
* Copyright (C) 2017 BonitaSoft S.A.
* BonitaSoft is a trademark of BonitaSoft SA.
* This software file is BONITASOFT CONFIDENTIAL. Not For Distribution.
* For commercial licensing information, contact:
* BonitaSoft, 32 rue Gustave Eiffel 38000 Grenoble
* or BonitaSoft US, 51 Federal Street, Suite 305, San Francisco, CA 94107
*******************************************************************************/
package org.bonitasoft.studio.la.ui.control;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
public class SelectSingleApplicationDescriptorPage extends SelectApplicationDescriptorPage {
public SelectSingleApplicationDescriptorPage(RepositoryAccessor repositoryAccessor) {
super(repositoryAccessor);
}
@Override
protected TableViewer createTableViewer(Composite mainComposite) {
return new TableViewer(mainComposite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
}
public IRepositoryFileStore getSingleSelection() {
if (applicationsTableViewer.getSelection().isEmpty()) {
throw new IllegalStateException("Selection is empty");
}
return (IRepositoryFileStore) ((IStructuredSelection) applicationsTableViewer.getSelection()).getFirstElement();
}
}
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