Commit 3fec8b9a authored by Romain Bioteau's avatar Romain Bioteau Committed by Adrien

feat(projectView) implement a project view using the cnf framework (#1275)

* use this explorer in all our editors
* enable the link with the editor by default
* add the bonita icon
* add viewer filters

[BS-18561](https://bonitasoft.atlassian.net/browse/BS-18561)
parent d0c16a47
......@@ -534,11 +534,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
version="0.0.0"
unpack="false"/>
<plugin
id="org.bonitasoft.studio.explorer"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>
......@@ -56,7 +56,9 @@ Require-Bundle: org.bonitasoft.studio.diagram,
org.eclipse.core.net,
org.eclipse.osgi,
org.eclipse.e4.core.di;bundle-version="1.4.0",
org.bonitasoft.studio.designer;bundle-version="7.7.0"
org.bonitasoft.studio.designer;bundle-version="7.7.0",
org.eclipse.ui.navigator,
org.eclipse.ui.navigator.resources
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: javax.inject;version="1.0.0",
......
......@@ -48,4 +48,5 @@ online_documentation=Online documentation
RecentlyModified=Recently modified
renameLabel=Rename diagram...
importLabel=Import
openUidLog=Bonita UI-Designer log
\ No newline at end of file
openUidLog=Bonita UI-Designer log
projectExplorer=Project explorer
\ No newline at end of file
......@@ -525,6 +525,15 @@
name="%Execution"
restorable="true">
</view>
<view
category="org.bonitasoft.studio.application.bonita"
class="org.bonitasoft.studio.application.views.BonitaProjectExplorer"
icon="icons/resource_persp.png"
id="org.bonitasoft.studio.application.project.explorer"
inject="true"
name="%projectExplorer"
restorable="true">
</view>
</extension>
<extension
point="org.eclipse.ui.activities">
......@@ -954,5 +963,117 @@
class="org.bonitasoft.studio.application.RemoveQuickAccessProcessor">
</processor>
</extension>
<extension
point="org.eclipse.ui.navigator.viewer">
<viewer
viewerId="org.bonitasoft.studio.application.project.explorer">
<popupMenu
allowsPlatformContributions="false"
id="org.bonitasoft.studio.application.project.explorer#PopupMenu">
<insertionPoint name="group.new"/>
<insertionPoint
name="group.open"
separator="true"/>
<insertionPoint name="group.openWith"/>
<insertionPoint name="group.edit"
separator="true"/>
<insertionPoint name="group.reorganize" />
<insertionPoint
name="group.port"
separator="true"/>
<insertionPoint
name="group.build"
separator="true"/>
<insertionPoint
name="group.generate"
separator="true"/>
<insertionPoint
name="group.search"
separator="true"/>
<insertionPoint
name="additions"
separator="true"/>
<insertionPoint
name="group.properties"
separator="true"/>
</popupMenu>
</viewer>
<viewerContentBinding
viewerId="org.bonitasoft.studio.application.project.explorer">
<includes>
<contentExtension
pattern="org.bonitasoft.studio.application.navigatorContent">
</contentExtension>
<contentExtension
pattern="org.eclipse.ui.navigator.resources.linkHelper">
</contentExtension>
<contentExtension
pattern="org.eclipse.ui.navigator.resources.filters.*">
</contentExtension>
<contentExtension
pattern="org.eclipse.jdt.java.ui.javaLinkHelper">
</contentExtension>
<contentExtension
pattern="org.eclipse.jdt.java.ui.filters.*">
</contentExtension>
<contentExtension
pattern="org.bonitasoft.studio.application.project.explorer.filters.*">
</contentExtension>
</includes>
<excludes>
<contentExtension
pattern="org.eclipse.ui.navigator.resources.filters.closedProject">
</contentExtension>
</excludes>
</viewerContentBinding>
</extension>
<extension
point="org.eclipse.ui.navigator.navigatorContent">
<navigatorContent
activeByDefault="true"
contentProvider="org.eclipse.jdt.internal.ui.navigator.JavaNavigatorContentProvider"
id="org.bonitasoft.studio.application.navigatorContent"
labelProvider="org.eclipse.jdt.internal.ui.navigator.JavaNavigatorLabelProvider"
name="Bonita Project Explorer Content">
<triggerPoints>
<or>
<adapt type="org.eclipse.core.resources.IProject" >
<test property="org.eclipse.core.resources.projectNature" value="org.eclipse.jdt.core.javanature"/>
</adapt>
<instanceof value="org.eclipse.core.resources.IResource" />
<instanceof value="org.eclipse.jdt.core.IJavaElement" />
<instanceof value="org.eclipse.jdt.core.IJarEntryResource" />
<instanceof value="org.eclipse.jdt.internal.ui.packageview.PackageFragmentRootContainer" />
</or>
</triggerPoints>
<possibleChildren>
<or>
<instanceof value="org.eclipse.core.resources.IResource" />
<instanceof value="org.eclipse.jdt.core.IJavaElement" />
<instanceof value="org.eclipse.jdt.core.IJarEntryResource" />
<instanceof value="org.eclipse.jdt.internal.ui.packageview.PackageFragmentRootContainer" />
</or>
</possibleChildren>
<actionProvider
class="org.bonitasoft.studio.application.views.CustomOpenActionProvider"
id="org.bonitasoft.studio.application.views.OpenActionProvider">
</actionProvider>
<commonSorter
class="org.eclipse.ui.internal.navigator.resources.workbench.ResourceExtensionSorter"
id="org.eclipse.ui.navigator.resources.sorters.defaultSorter">
</commonSorter>
</navigatorContent>
<commonFilter
activeByDefault="true"
class="org.bonitasoft.studio.application.views.filters.ProvidedContentFilter"
description="Artifacts that are provided by Bonita and should nor be edited"
id="org.bonitasoft.studio.application.project.explorer.filters.providedContent"
name="Provided content"
visibleInUI="true">
</commonFilter>
</extension>
</plugin>
......@@ -12,35 +12,57 @@
* 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.explorer.filters;
package org.bonitasoft.studio.application.views;
import java.util.Objects;
import javax.inject.Inject;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.navigator.CommonNavigator;
import org.eclipse.ui.navigator.CommonViewer;
public class CurrentProjectFilter extends ViewerFilter {
public class BonitaProjectExplorer extends CommonNavigator {
public static final String ID = "org.bonitasoft.studio.application.project.explorer";
@Inject
private RepositoryAccessor repositoryAccessor;
public CurrentProjectFilter(RepositoryAccessor repositoryAccessor) {
this.repositoryAccessor = repositoryAccessor;
@Override
protected Object getInitialInput() {
return repositoryAccessor.getWorkspace().getRoot();
}
public BonitaProjectExplorer() {
super();
}
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
IProject currentProject = repositoryAccessor.getCurrentRepository().getProject();
if (element instanceof JavaProject) {
JavaProject project = (JavaProject) element;
return Objects.equals(currentProject.getName(), project.getElementName());
} else if (element instanceof IProject) {
IProject project = (IProject) element;
return Objects.equals(currentProject, project);
}
return true;
public void createPartControl(Composite aParent) {
super.createPartControl(aParent);
setLinkingEnabled(true);
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.navigator.CommonNavigator#createCommonViewerObject(org.eclipse.swt.widgets.Composite)
*/
@Override
protected CommonViewer createCommonViewerObject(Composite aParent) {
CommonViewer commonViewer = new CommonViewer(getViewSite().getId(), aParent,
SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL) {
/*
* (non-Javadoc)
* @see org.eclipse.ui.navigator.CommonViewer#initDragAndDrop()
*/
@Override
protected void initDragAndDrop() {
}
};
return commonViewer;
}
}
......@@ -12,55 +12,50 @@
* 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.explorer;
package org.bonitasoft.studio.application.views;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.eclipse.jdt.ui.actions.OpenEditorActionGroup;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.ICommonActionConstants;
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
/**
* The activator class controls the plug-in life cycle
*/
public class BonitaPackageExplorerPlugin extends AbstractUIPlugin {
public class CustomOpenActionProvider extends CommonActionProvider {
// The plug-in ID
public static final String PLUGIN_ID = "org.bonitasoft.studio.explorer"; //$NON-NLS-1$
private OpenEditorActionGroup openFileAction;
// The shared instance
private static BonitaPackageExplorerPlugin plugin;
private ICommonViewerWorkbenchSite viewSite = null;
/**
* The constructor
*/
public BonitaPackageExplorerPlugin() {
}
private boolean contribute = false;
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
public void init(ICommonActionExtensionSite aConfig) {
if (aConfig.getViewSite() instanceof ICommonViewerWorkbenchSite) {
viewSite = (ICommonViewerWorkbenchSite) aConfig.getViewSite();
openFileAction = new OpenEditorActionGroup((IViewPart) viewSite.getPart());
contribute = true;
}
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
public void fillContextMenu(IMenuManager aMenu) {
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static BonitaPackageExplorerPlugin getDefault() {
return plugin;
@Override
public void fillActionBars(IActionBars theActionBars) {
if (!contribute) {
return;
}
openFileAction.setContext(getContext());
if (openFileAction.getOpenAction().isEnabled())
theActionBars.setGlobalActionHandler(ICommonActionConstants.OPEN,
openFileAction.getOpenAction());
}
}
/**
* Copyright (C) 2018 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.application.views.filters;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
public class ProvidedContentFilter extends ViewerFilter {
private static final Set<IPath> HIDDEN_RESOURCES = new HashSet<>();
static {
HIDDEN_RESOURCES.add(Path.fromPortableString("database_connectors_properties"));
HIDDEN_RESOURCES.add(Path.fromPortableString("META-INF"));
HIDDEN_RESOURCES.add(Path.fromPortableString("h2_database"));
HIDDEN_RESOURCES.add(Path.fromPortableString("process_configurations"));
HIDDEN_RESOURCES.add(Path.fromPortableString("template"));
HIDDEN_RESOURCES.add(Path.fromPortableString("src-providedGroovy"));
HIDDEN_RESOURCES.add(Path.fromOSString("org.eclipse.pde.core.requiredPlugins"));
HIDDEN_RESOURCES.add(Path.fromOSString("GROOVY_DSL_SUPPORT"));
HIDDEN_RESOURCES.add(Path.fromOSString("build.properties"));
HIDDEN_RESOURCES.add(Path.fromOSString("web_widgets/.metadata"));
HIDDEN_RESOURCES.add(Path.fromOSString("web_pages/.metadata"));
HIDDEN_RESOURCES.add(Path.fromOSString("web_fragments/.metadata"));
}
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IPackageFragmentRoot) {
IResource resource = ((IPackageFragmentRoot) element).getAdapter(IResource.class);
if (resource instanceof IResource) {
return !HIDDEN_RESOURCES
.contains(resource.getProjectRelativePath());
}
}
if (element instanceof ClassPathContainer) {
return !HIDDEN_RESOURCES
.contains(((ClassPathContainer) element).getClasspathEntry().getPath());
}
if (element instanceof IProject
&& (((IProject) element).getName().equals("server_configuration")
//Hide rest api projects for now
|| ((IProject) element).getLocation().toFile().getParentFile().getName()
.equals("restAPIExtensions"))) {
return false;
}
//Hide closed projects
if (element instanceof IJavaElement) {
return ((IJavaElement) element).getJavaProject().getProject().isOpen();
}
if (element instanceof IResource) {
return ((IResource) element).getProject().isOpen()
&& !HIDDEN_RESOURCES.contains(((IResource) element).getProjectRelativePath());
}
return true;
}
}
......@@ -38,7 +38,7 @@ public class PerspectiveJavaFactory extends AbstractPerspectiveFactory {
// Bottom left.
final IFolderLayout leftView = layout.createFolder(
"leftView", IPageLayout.LEFT, 0.2f, editorArea);
leftView.addView("org.bonitasoft.studio.explorer");
leftView.addView("org.bonitasoft.studio.application.project.explorer");
leftView.addView(IPageLayout.ID_OUTLINE);
layout.setFixed(true);
}
......
......@@ -34,7 +34,7 @@ public class TextEditorPerspectiveFactory extends AbstractPerspectiveFactory {
final IFolderLayout leftView = layout.createFolder(
"leftView", IPageLayout.LEFT, 0.2f, editorArea);
leftView.addView("org.bonitasoft.studio.explorer");
leftView.addView("org.bonitasoft.studio.application.project.explorer");
}
protected void configureIntroView(final IPageLayout layout) {
......
......@@ -33,8 +33,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.databinding,
org.eclipse.core.databinding.beans,
org.eclipse.jface.databinding,
org.bonitasoft.studio.tests-utils;bundle-version="7.1.0";resolution:=optional,
org.bonitasoft.studio.explorer
org.bonitasoft.studio.tests-utils;bundle-version="7.1.0";resolution:=optional
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.diagram.custom;
......
......@@ -18,7 +18,6 @@ import org.bonitasoft.studio.common.perspectives.AbstractPerspectiveFactory;
import org.bonitasoft.studio.common.perspectives.BonitaPerspectivesUtils;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.diagram.custom.views.BPMNPaletteView;
import org.bonitasoft.studio.explorer.parts.BonitaPackageExplorerPart;
import org.bonitasoft.studio.migration.model.report.Report;
import org.bonitasoft.studio.model.process.diagram.part.ProcessDiagramEditor;
import org.eclipse.emf.ecore.EObject;
......@@ -76,10 +75,9 @@ public class PerspectiveProcessFactory extends AbstractPerspectiveFactory {
(float) 0.2,
editorArea);
left.addView(BPMNPaletteView.ID);
left.addView(BonitaPackageExplorerPart.VIEW_ID);
layout.getViewLayout(BPMNPaletteView.ID).setCloseable(false);
layout.getViewLayout(BPMNPaletteView.ID).setMoveable(false);
left.addPlaceholder("org.bonitasoft.studio.migration.view");
left.addView("org.bonitasoft.studio.application.project.explorer");
}
/*
......
<?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.8"/>
<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.explorer</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>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bonita package explorer
Bundle-SymbolicName: org.bonitasoft.studio.explorer;singleton:=true
Bundle-Version: 7.8.0.qualifier
Bundle-Activator: org.bonitasoft.studio.explorer.BonitaPackageExplorerPlugin
Bundle-Vendor: Bonitasoft S.A.
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jdt.ui,
org.eclipse.core.resources,
org.bonitasoft.studio.common.repository,
org.eclipse.e4.core.commands,
org.apache.commons.lang,
org.junit,
org.mockito,
assertj-core;bundle-version="3.6.1",
org.eclipse.jdt.core
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: org.bonitasoft.studio.explorer
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.explorer.parts
src.excludes = src-test/java/,\
src-test/resources/
output.. = bin/
bin.includes = META-INF/,\
.,\
messages*.properties,\
plugin.xml,\
icons/
source.. = src/
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<view
category="org.bonitasoft.studio.application.bonita"
class="org.bonitasoft.studio.explorer.parts.BonitaPackageExplorerPart"
icon="icons/bonitasoft-icon-16-16-transparent.png"
id="org.bonitasoft.studio.explorer"
name="Bonita package explorer"
restorable="true">
</view>
</extension>
</plugin>
<?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>7.8.0-SNAPSHOT</version>
</parent>
<groupId>org.bonitasoft.studio.bundles.plugins</groupId>
<artifactId>org.bonitasoft.studio.explorer</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
/**
* Copyright (C) 2018 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.explorer.filters;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.internal.core.JavaProject;
import org.junit.Test;
public class CurrentProjectFilterTest {
@Test
public void should_only_accept_current_project() {
IProject currentProject = mock(IProject.class);
IProject otherProject = mock(IProject.class);
Repository currentRepo = mock(Repository.class);
when(currentRepo.getProject()).thenReturn(currentProject);
RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class);
when(repositoryAccessor.getCurrentRepository()).thenReturn(currentRepo);
CurrentProjectFilter filter = new CurrentProjectFilter(repositoryAccessor);
assertThat(filter.select(null, null, otherProject)).isFalse();
assertThat(filter.select(null, null, currentProject)).isTrue();
}
@SuppressWarnings("restriction")
@Test
public void should_only_accept_current_java_project() {
JavaProject currentJavaProject = mock(JavaProject.class);
when(currentJavaProject.getElementName()).thenReturn("default");
JavaProject otherJavaProject = mock(JavaProject.class);
when(otherJavaProject.getElementName()).thenReturn("aProject");
IProject currentProject = mock(IProject.class);
when(currentProject.getName()).thenReturn("default");
Repository currentRepo = mock(Repository.class);
when(currentRepo.getProject()).thenReturn(currentProject);
RepositoryAccessor repositoryAccessor = mock(RepositoryAccessor.class);
when(repositoryAccessor.getCurrentRepository()).thenReturn(currentRepo);
CurrentProjectFilter filter = new CurrentProjectFilter(repositoryAccessor);
assertThat(filter.select(null, null, otherJavaProject)).isFalse();
assertThat(filter.select(null, null, currentJavaProject)).isTrue();
}
}