Commit 07d0b4c7 authored by Adrien's avatar Adrien Committed by Romain Bioteau

feat(project explorer) display and edit active environment (#1516)

* Add a LocalEnvironmentFileStore (in memory) in order to display the
local env in the explorer
* Display in the explorer the active environment
* Add an action on environment files to set the active environment

closes [BS-19115](https://bonitasoft.atlassian.net/browse/BS-19115)
parent ac080e53
......@@ -14,6 +14,8 @@
*/
package org.bonitasoft.studio.application.handler;
import java.util.Optional;
import org.bonitasoft.studio.application.views.provider.UIDArtifactFilters;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager;
......@@ -33,16 +35,16 @@ import org.eclipse.ui.ide.IDE;
public class OpenHandler extends AbstractHandler {
private FileStoreFinder selectionFinder = new FileStoreFinder();
private FileStoreFinder fileStoreFinder = new FileStoreFinder();
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = selectionFinder.getSelectionInExplorer();
ISelection selection = fileStoreFinder.getSelectionInExplorer();
IResource resource = ((IAdaptable) ((IStructuredSelection) selection).getFirstElement()).getAdapter(IResource.class);
IRepositoryFileStore fileStore = RepositoryManager.getInstance().getCurrentRepository()
.getFileStore(resource);
if (fileStore != null) {
fileStore.open();
Optional<? extends IRepositoryFileStore> fileStore = fileStoreFinder.findFileStore(resource.getName(),
RepositoryManager.getInstance().getCurrentRepository());
if (fileStore.isPresent()) {
fileStore.get().open();
} else {
try {
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), (IFile) resource);
......@@ -59,7 +61,7 @@ public class OpenHandler extends AbstractHandler {
*/
@Override
public boolean isEnabled() {
ISelection selection = selectionFinder.getSelectionInExplorer();
ISelection selection = fileStoreFinder.getSelectionInExplorer();
if (selection instanceof IStructuredSelection
&& ((IStructuredSelection) selection).size() == 1) {
Object sel = ((IStructuredSelection) selection).getFirstElement();
......
......@@ -14,6 +14,13 @@
*/
package org.bonitasoft.studio.application.views.provider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.jdt.internal.ui.navigator.JavaNavigatorContentProvider;
public class BonitaExplorerContentProvider extends JavaNavigatorContentProvider {
......@@ -31,8 +38,24 @@ public class BonitaExplorerContentProvider extends JavaNavigatorContentProvider
if (UIDArtifactFilters.isUIDArtifact(parentElement)) {
return new Object[0];
}
if (parentElement instanceof IFolder && isEnvironmentsFolder((IFolder) parentElement)) {
return addLocalEnvironment(parentElement);
}
return super.getChildren(parentElement);
}
// The local environment is not persisted in a fileStore, we must 'fake' it to display it.
private Object[] addLocalEnvironment(Object parentElement) {
IFolder parent = (IFolder) parentElement;
IFile localEnv = parent.getFile("Local.xml");
List<Object> children = new ArrayList<>();
children.add(localEnv);
children.addAll(Arrays.asList(super.getChildren(parentElement)));
return children.toArray();
}
private boolean isEnvironmentsFolder(IFolder parentElement) {
return Objects.equals(parentElement.getName(), "environements");
}
}
......@@ -14,17 +14,15 @@
*/
package org.bonitasoft.studio.application.views.provider;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.filestore.FileStoreFinder;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
......@@ -38,17 +36,19 @@ import org.eclipse.ui.navigator.ICommonContentExtensionSite;
public class BonitaExplorerLabelProvider extends JavaNavigatorLabelProvider {
private PackageExplorerProblemsDecorator packageExplorerProblemsDecorator;
private FileStoreFinder fileStoreFinder;
@Override
public void init(ICommonContentExtensionSite commonContentExtensionSite) {
super.init(commonContentExtensionSite);
packageExplorerProblemsDecorator = new PackageExplorerProblemsDecorator();
fileStoreFinder = new FileStoreFinder();
}
/*
* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.navigator.JavaNavigatorLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
* @see org.eclipse.jdt.internal.ui.navigator.JavaNavigatorLabelProvider#addListener(org.eclipse.jface.viewers.
* ILabelProviderListener)
*/
@Override
public void addListener(ILabelProviderListener listener) {
......@@ -58,7 +58,8 @@ public class BonitaExplorerLabelProvider extends JavaNavigatorLabelProvider {
/*
* (non-Javadoc)
* @see org.eclipse.jdt.internal.ui.navigator.JavaNavigatorLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
* @see org.eclipse.jdt.internal.ui.navigator.JavaNavigatorLabelProvider#removeListener(org.eclipse.jface.viewers.
* ILabelProviderListener)
*/
@Override
public void removeListener(ILabelProviderListener listener) {
......@@ -74,12 +75,12 @@ public class BonitaExplorerLabelProvider extends JavaNavigatorLabelProvider {
}
if (!(element instanceof IJavaElement)) {
if (element instanceof IResource) {
IRepositoryFileStore fileStore = repositoryManager.getCurrentRepository().getFileStore((IResource) element);
if (fileStore != null) {
if (fileStore.getIcon() != null) {
return packageExplorerProblemsDecorator.decorateImage(fileStore.getIcon(), element);
}
return super.getImage(element);
Optional<? extends IRepositoryFileStore> fileStore = asFileStore(element, repositoryManager);
if (fileStore.isPresent()) {
return fileStore
.map(IRepositoryFileStore::getIcon)
.map(icon -> packageExplorerProblemsDecorator.decorateImage(icon, element))
.orElse(super.getImage(element));
}
}
Optional<IRepositoryStore<? extends IRepositoryFileStore>> repositoryStore = repositoryManager
......@@ -92,7 +93,6 @@ public class BonitaExplorerLabelProvider extends JavaNavigatorLabelProvider {
return super.getImage(element);
}
@Override
public StyledString getStyledText(Object element) {
RepositoryManager repositoryManager = RepositoryManager.getInstance();
......@@ -107,25 +107,20 @@ public class BonitaExplorerLabelProvider extends JavaNavigatorLabelProvider {
String displayName = iRepositoryStore.getDisplayName();
return new StyledString(displayName != null ? displayName : iRepositoryStore.getName());
}
IRepositoryFileStore fStore = asFileStore(element, repositoryManager);
if (fStore != null && Objects.equals(fStore.getResource(), element)) {
return fStore.getStyledString();
}
return asFileStore(element, repositoryManager)
.filter(fStore -> Objects.equals(fStore.getResource(), element))
.map(IRepositoryFileStore::getStyledString)
.orElse(super.getStyledText(element));
}
return super.getStyledText(element);
}
private IRepositoryFileStore asFileStore(Object element, RepositoryManager repositoryManager) {
try {
if (element instanceof IResource && ((IResource) element).getLocation() != null) {
return repositoryManager.getCurrentRepository()
.asRepositoryFileStore(((IResource) element).getLocation().toFile().toPath(), false);
}
} catch (IOException | CoreException e) {
BonitaStudioLog.error(e);
}
return null;
private Optional<? extends IRepositoryFileStore> asFileStore(Object element, RepositoryManager repositoryManager) {
return Optional.ofNullable(element)
.filter(IResource.class::isInstance)
.map(IResource.class::cast)
.flatMap(resource -> fileStoreFinder.findFileStore(resource.getName(),
repositoryManager.getCurrentRepository()));
}
public static boolean isFolder(Object element, String folderName) {
......
......@@ -17,8 +17,10 @@ package org.bonitasoft.studio.application.views.provider;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.filestore.FileStoreFinder;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.eclipse.core.internal.resources.File;
import org.eclipse.core.resources.IFile;
......@@ -42,6 +44,7 @@ public class CustomOpenActionProvider extends CommonActionProvider {
private ICommonViewerWorkbenchSite viewSite = null;
private boolean contribute = false;
private RepositoryAccessor repositoryAccessor;
private FileStoreFinder fileStoreFinder;
@Override
public void init(ICommonActionExtensionSite aConfig) {
......@@ -52,9 +55,9 @@ public class CustomOpenActionProvider extends CommonActionProvider {
}
repositoryAccessor = new RepositoryAccessor();
repositoryAccessor.init();
fileStoreFinder = new FileStoreFinder();
}
@Override
public void fillActionBars(IActionBars theActionBars) {
if (!contribute) {
......@@ -81,8 +84,9 @@ public class CustomOpenActionProvider extends CommonActionProvider {
@Override
public void run(IStructuredSelection selection) {
if (!checkEnabled(selection))
if (!checkEnabled(selection)) {
return;
}
run(selection.toArray());
}
......@@ -92,12 +96,12 @@ public class CustomOpenActionProvider extends CommonActionProvider {
for (Object element : elements) {
if (element instanceof File || UIDArtifactFilters.isUIDArtifact(element)) {
IRepositoryFileStore fileStore = repositoryAccessor.getCurrentRepository()
.getFileStore((IResource) element);
if (fileStore != null) {
fileStore.open();
Optional<? extends IRepositoryFileStore> fileStore = fileStoreFinder
.findFileStore(((IResource) element).getName(), repositoryAccessor.getCurrentRepository());
if (fileStore.isPresent()) {
fileStore.get().open();
continue;
}
} ;
}
elementsToKeep.add(element);
}
......@@ -106,18 +110,23 @@ public class CustomOpenActionProvider extends CommonActionProvider {
}
private boolean checkEnabled(IStructuredSelection selection) {
if (selection.isEmpty())
if (selection.isEmpty()) {
return false;
}
for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
Object element = iter.next();
if (element instanceof ISourceReference)
if (element instanceof ISourceReference) {
continue;
if (element instanceof IFile)
}
if (element instanceof IFile) {
continue;
if (UIDArtifactFilters.isUIDArtifact(element))
}
if (UIDArtifactFilters.isUIDArtifact(element)) {
continue;
if (JavaModelUtil.isOpenableStorage(element))
}
if (JavaModelUtil.isOpenableStorage(element)) {
continue;
}
return false;
}
return true;
......
......@@ -108,7 +108,7 @@ public class FileStoreFinder {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(BONITA_PROJECT_EXPLORER_ID));
}
private Optional<? extends IRepositoryFileStore> findFileStore(String resourceName, Repository currentRepository) {
public Optional<? extends IRepositoryFileStore> findFileStore(String resourceName, Repository currentRepository) {
return currentRepository.getAllStores().stream()
.map(IRepositoryStore::getChildren)
.flatMap(Collection::stream)
......
......@@ -26,6 +26,7 @@ import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.bonitasoft.studio.common.extension.BonitaStudioExtensionRegistryManager;
import org.bonitasoft.studio.common.jface.BonitaErrorDialog;
......@@ -122,29 +123,21 @@ public abstract class AbstractRepositoryStore<T extends IRepositoryFileStore> im
} catch (final MigrationException e) {
BonitaStudioLog.error(e);
if (!FileActionDialog.getDisablePopup()) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
new BonitaErrorDialog(Display.getDefault().getActiveShell(), Messages.migrationFailedTitle,
Messages.migrationFailedMessage, e).open();
}
});
Display.getDefault()
.syncExec(() -> new BonitaErrorDialog(Display.getDefault().getActiveShell(),
Messages.migrationFailedTitle,
Messages.migrationFailedMessage, e).open());
}
return null;
} catch (final IOException e) {
BonitaStudioLog.error(e);
if (!FileActionDialog.getDisablePopup()) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
new BonitaErrorDialog(Display.getDefault().getActiveShell(), Messages.importedFileIsInvalidTitle,
Display.getDefault()
.syncExec(() -> new BonitaErrorDialog(Display.getDefault().getActiveShell(),
Messages.importedFileIsInvalidTitle,
Messages.bind(
Messages.importedFileIsInvalid, fileName),
e).open();
}
});
e).open());
}
return null;
}
......@@ -320,13 +313,7 @@ public abstract class AbstractRepositoryStore<T extends IRepositoryFileStore> im
}
private Function<IResource, T> toFileStore() {
return new Function<IResource, T>() {
@Override
public T apply(final IResource resource) {
return createRepositoryFileStore(resource.getName());
}
};
return resource -> createRepositoryFileStore(resource.getName());
}
@Override
......@@ -378,28 +365,26 @@ public abstract class AbstractRepositoryStore<T extends IRepositoryFileStore> im
@Override
public void migrate(final IProgressMonitor monitor) throws CoreException, MigrationException {
for (final IRepositoryFileStore fs : getChildren()) {
if (!fs.isReadOnly() && fs.canBeShared()) {
final IResource r = fs.getResource();
if (r instanceof IFile && r.exists()) {
monitor.subTask(r.getName());
final IFile iFile = (IFile) r;
InputStream newIs;
try (final InputStream is = iFile.getContents()) {
newIs = handlePreImport(r.getName(), is);
if (!is.equals(newIs)) {
iFile.setContents(newIs, IResource.FORCE, monitor);
iFile.refreshLocal(IResource.DEPTH_ONE, monitor);
}
} catch (final IOException e) {
throw new MigrationException("Cannot migrate resource " + r.getName() + " (not a valid file)", e);
}
} else {
throw new MigrationException("Cannot migrate resource " + r.getName() + " (not a file)",
new IOException("Not an existing file :"
+ r.getLocation()));
List<IFile> filesToMigrate = getChildren().stream()
.filter(fs -> !fs.isReadOnly())
.filter(IRepositoryFileStore::canBeShared)
.map(IRepositoryFileStore::getResource)
.filter(IFile.class::isInstance)
.map(IFile.class::cast)
.filter(IFile::exists)
.collect(Collectors.toList());
for (IFile file : filesToMigrate) {
monitor.subTask(file.getName());
InputStream newIs;
try (final InputStream is = file.getContents()) {
newIs = handlePreImport(file.getName(), is);
if (!is.equals(newIs)) {
file.setContents(newIs, IResource.FORCE, monitor);
file.refreshLocal(IResource.DEPTH_ONE, monitor);
}
} catch (final IOException e) {
throw new MigrationException("Cannot migrate resource " + file.getName() + " (not a valid file)", e);
}
}
}
......
......@@ -136,7 +136,7 @@ public class BarExporterTest {
bot.button(IDialogConstants.FINISH_LABEL).click();
// click 'OK' button to close 'Export' shell
bot.waitUntil(new ShellIsActiveWithThreadSTacksOnFailure(Messages.exportSuccessTitle));
bot.waitUntil(new ShellIsActiveWithThreadSTacksOnFailure(Messages.exportSuccessTitle), 10000);
bot.button(IDialogConstants.OK_LABEL).click();
// wait the shell to close before checking creation of files
......
......@@ -65,7 +65,7 @@ public class TestDuplicate {
public String getFailureMessage() {
return "Duplicate has failed !";
}
});
}, 10000);
final DiagramRepositoryStore drs = RepositoryManager.getInstance().getRepositoryStore(DiagramRepositoryStore.class);
final MainProcess mainProcess = drs.getDiagram("DuplicatedTestDuplicateWithSeveralPool", "2.0").getContent();
......@@ -115,7 +115,7 @@ public class TestDuplicate {
public String getFailureMessage() {
return "Duplicate has failed !";
}
});
}, 10000);
}
}
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