Commit 539e0ea2 authored by Adrien's avatar Adrien Committed by Romain Bioteau

feat(project explorer) save dirty editors before to deploy (#1520)

closes [BS-19179](https://bonitasoft.atlassian.net/browse/BS-19179)
parent c744c636
......@@ -62,7 +62,8 @@ Require-Bundle: org.bonitasoft.studio.diagram,
org.bonitasoft.studio.businessobject;bundle-version="7.8.0",
org.eclipse.e4.ui.services;bundle-version="1.3.0",
org.eclipse.wst.xml.core,
org.eclipse.wst.html.core
org.eclipse.wst.html.core,
org.bonitasoft.studio.ui;bundle-version="7.9.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: javax.inject;version="1.0.0",
......
......@@ -18,8 +18,10 @@ import java.util.Optional;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.filestore.AbstractFileStore;
import org.bonitasoft.studio.common.repository.filestore.FileStoreFinder;
import org.bonitasoft.studio.common.repository.model.IDeployable;
import org.bonitasoft.studio.ui.dialog.SaveBeforeDeployDialog;
import org.bonitasoft.studio.ui.dialog.SaveBeforeDeployDialog.DeployStrategy;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
......@@ -36,7 +38,17 @@ public class DeployHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
selectionFinder
.findElementToDeploy(RepositoryManager.getInstance().getCurrentRepository())
.ifPresent(IDeployable::deploy);
.ifPresent(deployable -> {
if (deployable instanceof AbstractFileStore && ((AbstractFileStore) deployable).isDirty()) {
DeployStrategy choice = SaveBeforeDeployDialog.open(((AbstractFileStore) deployable).getName());
if (choice == DeployStrategy.SAVE_AND_DEPLOY) {
((AbstractFileStore) deployable).saveOpenedEditor();
} else if (choice == DeployStrategy.CANCEL) {
return; // cancel
}
}
deployable.deploy();
});
return null;
}
......@@ -49,12 +61,12 @@ public class DeployHandler extends AbstractHandler {
IResource resource = ((IAdaptable) selection.get().getFirstElement()).getAdapter(IResource.class);
if (resource != null) {
Repository currentRepository = RepositoryManager.getInstance().getCurrentRepository();
boolean resourceMatch = selectionFinder.findElementToDeploy(resource.getName(), currentRepository)
boolean resourceMatch = selectionFinder.findElementToDeploy(resource, currentRepository)
.isPresent();
if (!resourceMatch) {
IProject project = resource.getProject();
if (project != null) {
resourceMatch = selectionFinder.findElementToDeploy(project.getName(), currentRepository)
resourceMatch = selectionFinder.findElementToDeploy(project, currentRepository)
.isPresent();
}
}
......
......@@ -41,7 +41,7 @@ public class OpenHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = fileStoreFinder.getSelectionInExplorer();
IResource resource = ((IAdaptable) ((IStructuredSelection) selection).getFirstElement()).getAdapter(IResource.class);
Optional<? extends IRepositoryFileStore> fileStore = fileStoreFinder.findFileStore(resource.getName(),
Optional<? extends IRepositoryFileStore> fileStore = fileStoreFinder.findFileStore(resource,
RepositoryManager.getInstance().getCurrentRepository());
if (fileStore.isPresent()) {
fileStore.get().open();
......
......@@ -119,7 +119,7 @@ public class BonitaExplorerLabelProvider extends JavaNavigatorLabelProvider {
return Optional.ofNullable(element)
.filter(IResource.class::isInstance)
.map(IResource.class::cast)
.flatMap(resource -> fileStoreFinder.findFileStore(resource.getName(),
.flatMap(resource -> fileStoreFinder.findFileStore(resource,
repositoryManager.getCurrentRepository()));
}
......
......@@ -97,7 +97,7 @@ public class CustomOpenActionProvider extends CommonActionProvider {
for (Object element : elements) {
if (element instanceof File || UIDArtifactFilters.isUIDArtifact(element)) {
Optional<? extends IRepositoryFileStore> fileStore = fileStoreFinder
.findFileStore(((IResource) element).getName(), repositoryAccessor.getCurrentRepository());
.findFileStore(((IResource) element), repositoryAccessor.getCurrentRepository());
if (fileStore.isPresent()) {
fileStore.get().open();
continue;
......
......@@ -30,6 +30,7 @@ import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.bonitasoft.studio.common.repository.model.ReadFileStoreException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.IStructuredSelection;
......@@ -40,7 +41,9 @@ import org.junit.Test;
public class FileStoreFinderTest {
private static final String ORGA_NAME = "ACME.organization";
private static final String DIAGRAMS_FOLDER_NAME = "Diagrams";
private static final String ORGANIZATION_FOLDER_NAME = "Organization";
private static final String FILE_NAME = "ACME.organization";
private static final String DOCUMENT_NAME = "doc.pdf";
@Test
......@@ -48,7 +51,11 @@ public class FileStoreFinderTest {
FileStoreFinder finder = spy(FileStoreFinder.class);
IFile file = mock(IFile.class);
when(file.getName()).thenReturn(ORGA_NAME);
IFolder parent = mock(IFolder.class);
when(parent.getName()).thenReturn(ORGANIZATION_FOLDER_NAME);
when(file.getName()).thenReturn(FILE_NAME);
when(file.getParent()).thenReturn(parent);
IStructuredSelection selection = new StructuredSelection(file);
doReturn(Optional.of(selection)).when(finder).getCurrentStructuredSelection();
Repository repository = initRepository();
......@@ -56,7 +63,7 @@ public class FileStoreFinderTest {
Optional<IRenamable> elementToRename = finder.findElementToRename(repository);
assertThat(elementToRename).isPresent();
FileStoreWithInterface fileStore = (FileStoreWithInterface) elementToRename.get();
assertThat(fileStore.getName()).isEqualTo(ORGA_NAME);
assertThat(fileStore.getName()).isEqualTo(FILE_NAME);
when(file.getName()).thenReturn(DOCUMENT_NAME);
......@@ -69,7 +76,11 @@ public class FileStoreFinderTest {
FileStoreFinder finder = spy(FileStoreFinder.class);
IFile file = mock(IFile.class);
when(file.getName()).thenReturn(ORGA_NAME);
IFolder parent = mock(IFolder.class);
when(parent.getName()).thenReturn(ORGANIZATION_FOLDER_NAME);
when(file.getName()).thenReturn(FILE_NAME);
when(file.getParent()).thenReturn(parent);
IAdaptable adaptable = mock(IAdaptable.class);
when(adaptable.getAdapter(IResource.class)).thenReturn(file);
IStructuredSelection selection = new StructuredSelection(adaptable);
......@@ -79,7 +90,7 @@ public class FileStoreFinderTest {
Optional<IDeployable> elementToDeploy = finder.findElementToDeploy(repository);
assertThat(elementToDeploy).isPresent();
FileStoreWithInterface fileStore = (FileStoreWithInterface) elementToDeploy.get();
assertThat(fileStore.getName()).isEqualTo(ORGA_NAME);
assertThat(fileStore.getName()).isEqualTo(FILE_NAME);
when(file.getName()).thenReturn(DOCUMENT_NAME);
......@@ -87,17 +98,55 @@ public class FileStoreFinderTest {
assertThat(elementToDeploy).isEmpty();
}
@Test
public void should_find_correct_file_store_if_two_files_have_the_same_name() {
FileStoreFinder finder = spy(FileStoreFinder.class);
IFile file = mock(IFile.class);
IFolder parent = mock(IFolder.class);
when(parent.getName()).thenReturn(ORGANIZATION_FOLDER_NAME);
when(file.getName()).thenReturn(FILE_NAME);
when(file.getParent()).thenReturn(parent);
IStructuredSelection selection = new StructuredSelection(file);
doReturn(Optional.of(selection)).when(finder).getCurrentStructuredSelection();
Repository repository = initRepository();
Optional<? extends IRepositoryFileStore> selectedFileStore = finder.findSelectedFileStore(repository);
assertThat(selectedFileStore).isPresent();
assertThat(selectedFileStore.get().getName()).isEqualTo(FILE_NAME);
assertThat(selectedFileStore.get().getParentStore().getName()).isEqualTo(ORGANIZATION_FOLDER_NAME);
when(parent.getName()).thenReturn(DIAGRAMS_FOLDER_NAME);
selectedFileStore = finder.findSelectedFileStore(repository);
assertThat(selectedFileStore).isPresent();
assertThat(selectedFileStore.get().getName()).isEqualTo(FILE_NAME);
assertThat(selectedFileStore.get().getParentStore().getName()).isEqualTo(DIAGRAMS_FOLDER_NAME);
}
private Repository initRepository() {
Repository repository = mock(Repository.class);
IRepositoryStore<? extends IRepositoryFileStore> storeWithInterfaces = initStoreWithInterfaces();
IRepositoryStore<? extends IRepositoryFileStore> storeWithInterfaces2 = initStoreWithInterfaces2();
IRepositoryStore<? extends IRepositoryFileStore> storeWithoutInterface = initStoreWithoutInterface();
when(repository.getAllStores()).thenReturn(Arrays.asList(storeWithInterfaces, storeWithoutInterface));
when(repository.getAllStores())
.thenReturn(Arrays.asList(storeWithInterfaces, storeWithInterfaces2, storeWithoutInterface));
return repository;
}
private IRepositoryStore<? extends IRepositoryFileStore> initStoreWithInterfaces() {
IRepositoryStore<FileStoreWithInterface> repositoryStore = mock(IRepositoryStore.class);
FileStoreWithInterface fileStore = new FileStoreWithInterface(ORGA_NAME, repositoryStore);
when(repositoryStore.getName()).thenReturn(ORGANIZATION_FOLDER_NAME);
FileStoreWithInterface fileStore = new FileStoreWithInterface(FILE_NAME, repositoryStore);
when(repositoryStore.getChildren()).thenReturn(Arrays.asList(fileStore));
return repositoryStore;
}
private IRepositoryStore<? extends IRepositoryFileStore> initStoreWithInterfaces2() {
IRepositoryStore<FileStoreWithInterface> repositoryStore = mock(IRepositoryStore.class);
when(repositoryStore.getName()).thenReturn(DIAGRAMS_FOLDER_NAME);
FileStoreWithInterface fileStore = new FileStoreWithInterface(FILE_NAME, repositoryStore);
when(repositoryStore.getChildren()).thenReturn(Arrays.asList(fileStore));
return repositoryStore;
}
......
......@@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.bonitasoft.studio.common.jface.FileActionDialog;
......@@ -42,11 +43,13 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.e4.core.commands.ECommandService;
import org.eclipse.e4.core.commands.EHandlerService;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
......@@ -427,14 +430,13 @@ public abstract class AbstractFileStore
}
@SuppressWarnings("restriction")
protected void executeCommand(String command, Map<String, Object> parameters) {
protected Object executeCommand(String command, Map<String, Object> parameters) {
initServices();
ParameterizedCommand parameterizedCommand = eCommandService.createCommand(command, parameters);
if (eHandlerService.canExecute(parameterizedCommand)) {
eHandlerService.executeHandler(parameterizedCommand);
} else {
throw new RuntimeException(String.format("Can't execute command %s", parameterizedCommand.getId()));
return eHandlerService.executeHandler(parameterizedCommand);
}
throw new RuntimeException(String.format("Can't execute command %s", parameterizedCommand.getId()));
}
protected void initServices() {
......@@ -456,4 +458,26 @@ public abstract class AbstractFileStore
return name.toLowerCase().endsWith(extension) ? name.replace(extension, "") : name;
}
public boolean isDirty() {
return findOpenedEditor()
.map(IEditorPart::isDirty)
.orElse(false);
}
protected Optional<IEditorPart> findOpenedEditor() {
return EditorFinder.findOpenedEditor(this, this::validateEditorInstance);
}
public void saveOpenedEditor() {
EditorFinder.findOpenedEditor(this, this::validateEditorInstance)
.ifPresent(editor -> editor.doSave(new NullProgressMonitor()));
}
/**
* Should be overwritten by fileStores with dedicated editors!!
*/
protected boolean validateEditorInstance(IEditorPart editor) {
return true;
}
}
/*******************************************************************************
* Copyright (C) 2018 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.common.repository.filestore;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Function;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.CommonRepositoryPlugin;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
public class EditorFinder {
public static Optional<IEditorPart> findOpenedEditor(AbstractFileStore fileStore,
Function<IEditorPart, Boolean> editorInstanceValidator) {
if (PlatformUI.isWorkbenchRunning()
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
final String resourceName = fileStore.getResource().getName();
return Arrays.asList(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences())
.stream()
.filter(ref -> {
return getEditorInput(ref)
.map(IEditorInput::getName)
.filter(resourceName::equals)
.isPresent();
})
.map(ref -> ref.getEditor(false))
.filter(editorInstanceValidator::apply)
.findFirst();
}
return Optional.empty();
}
private static Optional<IEditorInput> getEditorInput(IEditorReference ref) {
try {
return Optional.of(ref.getEditorInput());
} catch (PartInitException e) {
BonitaStudioLog.error(e, CommonRepositoryPlugin.PLUGIN_ID);
} catch (NullPointerException e) {
BonitaStudioLog.log("There is an editor without input.");
}
return Optional.empty();
}
}
......@@ -52,7 +52,7 @@ public class FileStoreFinder {
}
public Optional<IRenamable> findElementToRename(IResource resource, Repository currentRepository) {
return findFileStore(resource.getName(), currentRepository)
return findFileStore(resource, currentRepository)
.filter(IRenamable.class::isInstance)
.map(IRenamable.class::cast)
.filter(IRenamable::canBeRenamed);
......@@ -65,11 +65,11 @@ public class FileStoreFinder {
if (element instanceof IAdaptable) {
IResource resource = ((IAdaptable) element).getAdapter(IResource.class);
if (resource != null) {
Optional<IDeployable> toDeploy = findElementToDeploy(resource.getName(), currentRepository);
Optional<IDeployable> toDeploy = findElementToDeploy(resource, currentRepository);
if (!toDeploy.isPresent()) {
IProject project = (resource).getProject();
if (project != null) {
toDeploy = findElementToDeploy(project.getName(), currentRepository);
toDeploy = findElementToDeploy(project, currentRepository);
}
}
return toDeploy.orElse(null);
......@@ -79,8 +79,8 @@ public class FileStoreFinder {
});
}
public Optional<IDeployable> findElementToDeploy(String resourceName, Repository currentRepository) {
return findFileStore(resourceName, currentRepository)
public Optional<IDeployable> findElementToDeploy(IResource resource, Repository currentRepository) {
return findFileStore(resource, currentRepository)
.filter(IDeployable.class::isInstance)
.map(IDeployable.class::cast);
}
......@@ -90,7 +90,7 @@ public class FileStoreFinder {
.map(selection -> {
Object element = selection.getFirstElement();
if (element instanceof IResource) {
return findFileStore(((IResource) element).getName(), currentRepository).orElse(null);
return findFileStore(((IResource) element), currentRepository).orElse(null);
}
return null;
});
......@@ -108,11 +108,16 @@ public class FileStoreFinder {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(BONITA_PROJECT_EXPLORER_ID));
}
public Optional<? extends IRepositoryFileStore> findFileStore(String resourceName, Repository currentRepository) {
public Optional<? extends IRepositoryFileStore> findFileStore(IResource resource, Repository currentRepository) {
return currentRepository.getAllStores().stream()
.map(IRepositoryStore::getChildren)
.flatMap(Collection::stream)
.filter(fileStore -> Objects.equals(fileStore.getName(), resourceName))
.filter(fileStore -> Objects.equals(fileStore.getName(), resource.getName()))
.filter(fileStore -> {
return resource instanceof IProject
? true
: Objects.equals(fileStore.getParentStore().getName(), resource.getParent().getName());
})
.findFirst();
}
......
......@@ -56,6 +56,7 @@ Require-Bundle: org.eclipse.ui,
org.bonitasoft.studio.tests-utils;bundle-version="7.1.0";resolution:=optional,
org.eclipse.e4.core.commands,
org.eclipse.e4.ui.model.workbench;bundle-version="2.0.1.v20170713-1800",
org.eclipse.e4.core.di.annotations
org.eclipse.e4.core.di.annotations,
org.bonitasoft.studio.ui
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
......@@ -80,12 +80,9 @@ import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import com.google.common.base.Function;
......@@ -113,7 +110,6 @@ public class DiagramFileStore extends EMFFileStore implements IDeployable, IRena
return (MainProcess) super.getContent();
}
@Override
public String getDisplayName() {
final String displayName = getResource().getLocation().removeFileExtension().lastSegment();
......@@ -130,7 +126,6 @@ public class DiagramFileStore extends EMFFileStore implements IDeployable, IRena
return URI.createPlatformResourceURI(fullPath.toOSString(), true);
}
@Override
public Image getIcon() {
return Pics.getImage("ProcessDiagramFile.gif", Activator.getDefault());
......@@ -182,32 +177,14 @@ public class DiagramFileStore extends EMFFileStore implements IDeployable, IRena
}
public DiagramEditor getOpenedEditor() {
if (PlatformUI.isWorkbenchRunning()
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
&& PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
final String resourceName = getResource().getName();
for (final IEditorReference ref : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getEditorReferences()) {
String inputName;
try {
final IEditorInput editorInput = ref.getEditorInput();
if (editorInput != null) {
inputName = editorInput.getName();
if (resourceName.equals(inputName)) {
final IEditorPart editor = ref.getEditor(false);
if (editor instanceof ProcessDiagramEditor) {
return (DiagramEditor) editor;
}
}
} else {
BonitaStudioLog.log("There is an editor without input.");
}
} catch (final PartInitException e) {
BonitaStudioLog.error(e, Activator.PLUGIN_ID);
}
}
}
return null;
return findOpenedEditor()
.map(DiagramEditor.class::cast)
.orElse(null);
}
@Override
protected boolean validateEditorInstance(IEditorPart editor) {
return editor instanceof ProcessDiagramEditor;
}
public List<AbstractProcess> getProcesses() {
......
......@@ -9,6 +9,9 @@
<elements xsi:type="commands:Command" xmi:id="_pL3WsPnPEea-3Os5NcIV0g" elementId="org.bonitasoft.studio.la.deploy.command" commandName="%deployApplication">
<parameters xmi:id="_tvi1sMI4EeiSmOxE9tpWmw" elementId="application" name="Application to deploy"/>
</elements>
<elements xsi:type="commands:Command" xmi:id="_kyZscPyMEeicTeF1RHOGZw" elementId="org.bonitasoft.studio.la.findOpenedEditor.command" commandName="findOpenedEditor">
<parameters xmi:id="_oYJrIPyMEeicTeF1RHOGZw" elementId="fileStore" name="File store" optional="false"/>
</elements>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_--2aUNKdEeaEE_Umqe0dXA" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler" xmi:id="_BKi10NKeEeaEE_Umqe0dXA" elementId="org.bonitasoft.studio.la.newHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.NewApplicationHandler" command="_0n838NKdEeaEE_Umqe0dXA"/>
......@@ -17,5 +20,6 @@
<elements xsi:type="commands:Handler" xmi:id="_cIN9cAomEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.exportHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.ExportApplicationHandler" command="_YHf6AAomEeekfeZYiUbzLg"/>
<elements xsi:type="commands:Handler" xmi:id="_kWFX8ApAEeekfeZYiUbzLg" elementId="org.bonitasoft.studio.la.importHandler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.ImportApplicationhandler" command="_g4OJ8ApAEeekfeZYiUbzLg"/>
<elements xsi:type="commands:Handler" xmi:id="_JVGowM6fEee2rb_HhIZr1w" elementId="org.bonitasoft.studio.la.handler.deployapplication" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.DeployApplicationHandler" command="_pL3WsPnPEea-3Os5NcIV0g"/>
<elements xsi:type="commands:Handler" xmi:id="_NaDQgPyNEeicTeF1RHOGZw" elementId="org.bonitasoft.studio.la.findOpenedEditor.handler" contributionURI="bundleclass://org.bonitasoft.studio.la/org.bonitasoft.studio.la.application.handler.FindOpenedEditorHandler" command="_kyZscPyMEeicTeF1RHOGZw"/>
</fragments>
</fragment:ModelFragments>
/*******************************************************************************
* Copyright (C) 2018 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.application.handler;
import java.util.Optional;
import javax.inject.Named;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.filestore.EditorFinder;
import org.bonitasoft.studio.la.application.repository.ApplicationFileStore;
import org.bonitasoft.studio.la.application.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.ui.editors.FilteredXMLEditor;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.ui.IEditorPart;
public class FindOpenedEditorHandler {
private static final String FILE_STORE_PARAMETER = "fileStore";
@Execute
public Optional<IEditorPart> execute(RepositoryAccessor repositoryAccessor,
@org.eclipse.e4.core.di.annotations.Optional @Named(FILE_STORE_PARAMETER) String fileStore) {
ApplicationFileStore application = repositoryAccessor.getRepositoryStore(ApplicationRepositoryStore.class)
.getChild(fileStore);
return application != null
? EditorFinder.findOpenedEditor(application, this::validateEditorInstance)
: Optional.empty();
}
protected boolean validateEditorInstance(IEditorPart editor) {
return editor instanceof FilteredXMLEditor;
}
}
......@@ -192,4 +192,14 @@ public class ApplicationFileStore extends AbstractFileStore implements IDeployab
return Optional.empty();
}
@Override
@SuppressWarnings("unchecked")
protected Optional<IEditorPart> findOpenedEditor() {
Map<String, Object> parameters = new HashMap<>();
parameters.put("fileStore", getName());
Optional<IEditorPart> editor = (Optional<IEditorPart>) executeCommand(
"org.bonitasoft.studio.la.findOpenedEditor.command", parameters);
return editor;
}
}
......@@ -27,4 +27,6 @@ delete=Delete
deleteDoneMessage=Files have been deleted.
deleteDoneTitle=Delete completed
deleteConfirmation=Delete confirmation
deleteConfirmationMessage=You are about to delete this file from your workspace:\n%s\n\nAre you sure?
\ No newline at end of file
deleteConfirmationMessage=You are about to delete this file from your workspace:\n%s\n\nAre you sure?
saveAndDeploy=Save and deploy
deployCurrent=Deploy current
\ No newline at end of file
/*******************************************************************************
* Copyright (C) 2018 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.ui.dialog;
import org.bonitasoft.studio.ui.i18n.Messages;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
public class SaveBeforeDeployDialog {
public static DeployStrategy open(String resourceName) {
int choice = MessageDialog.open(MessageDialog.QUESTION, Display.getDefault().getActiveShell(),
Messages.saveBeforeTitle,
String.format(Messages.saveBeforeMessage, resourceName),
SWT.NONE, Messages.saveAndDeploy, IDialogConstants.CANCEL_LABEL, Messages.deployCurrent);
switch (choice) {
case 2:
return DeployStrategy.DEPLOY_CURRENT;
case 1:
return DeployStrategy.CANCEL;
default:
return DeployStrategy.SAVE_AND_DEPLOY;
}
}
public enum DeployStrategy {
SAVE_AND_DEPLOY, DEPLOY_CURRENT, CANCEL
}
}
......@@ -52,5 +52,7 @@ public class Messages extends NLS {
public static String deleteDoneMessage;
public static String deleteConfirmation;
public static String deleteConfirmationMessage;
public static String saveAndDeploy;
public static String deployCurrent;
}
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