Commit f4ab8b83 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

BS-9209

parent 19a63b59
......@@ -69,8 +69,8 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
private static final class SearchPatternFilter extends PatternFilter {
@Override
protected boolean isLeafMatch(org.eclipse.jface.viewers.Viewer viewer, Object element) {
String labelText = ((ILabelProvider) ((StructuredViewer) viewer).getLabelProvider()).getText(element);
protected boolean isLeafMatch(final org.eclipse.jface.viewers.Viewer viewer, final Object element) {
final String labelText = ((ILabelProvider) ((StructuredViewer) viewer).getLabelProvider()).getText(element);
if(labelText == null) {
return false;
......@@ -78,8 +78,8 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
if(wordMatches(labelText)){
return true ;
}else{
for(EAttribute attribute : ((EObject) element).eClass().getEAllAttributes()){
Object value = ((EObject) element).eGet(attribute) ;
for(final EAttribute attribute : ((EObject) element).eClass().getEAllAttributes()){
final Object value = ((EObject) element).eGet(attribute) ;
if( value != null && attribute.getEType().getName().equals("EString") && wordMatches(value.toString())){
return true ;
}
......@@ -97,7 +97,7 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
private final AdapterFactoryLabelProvider adapterFactoryLabelProvider = new AdapterFactoryLabelProvider(adapterFactory){
@Override
public String getText(Object object) {
public String getText(final Object object) {
final EStructuralFeature eContainingFeature = ((EObject)object).eContainingFeature();
if(eContainingFeature != null && eContainingFeature.equals(ProcessPackage.eINSTANCE.getAssignable_Filters())){
return "Filter "+((Element) object).getName() ;
......@@ -118,7 +118,7 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
* Constructs a TreeViewer with the default root editpart.
*/
public BonitaTreeViewer() {
RootTreeEditPart rep = new RootTreeEditPart();
final RootTreeEditPart rep = new RootTreeEditPart();
setRootEditPart(rep);
}
......@@ -132,7 +132,7 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
* @return the control
*/
@Override
public Control createControl(Composite parent) {
public Control createControl(final Composite parent) {
parent.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
final Composite mainComposite = new Composite(parent, SWT.BORDER);
mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
......@@ -147,7 +147,8 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
treeViewer.getTree().addListener(SWT.MouseDoubleClick, new Listener() {
public void handleEvent(Event event) {
@Override
public void handleEvent(final Event event) {
handlTreeDoubleClick();
}
......@@ -159,7 +160,7 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
private TreeViewer createFilteredTree(final Composite mainComposite) {
PatternFilter filter = new SearchPatternFilter() ;
final PatternFilter filter = new SearchPatternFilter() ;
filter.setIncludeLeadingWildcard(true) ;
filteredTree = new FilteredTree(mainComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL,filter,true);
final TreeViewer treeViewer = filteredTree.getViewer();
......@@ -184,24 +185,24 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
public void setDiagramEditPart(final DiagramEditPart diagramEditPart){
this.diagramEditPart = diagramEditPart ;
if(filteredTree != null){
EObject resolveSemanticElement = ((IGraphicalEditPart) diagramEditPart).resolveSemanticElement();
final EObject resolveSemanticElement = ((IGraphicalEditPart) diagramEditPart).resolveSemanticElement();
filteredTree.getViewer().setInput(resolveSemanticElement) ;
diagramEditPart.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
public void selectionChanged(final SelectionChangedEvent event) {
if (!filteredTree.isDisposed()) {
filteredTree.getViewer().refresh();
final EditPartViewer viewer = diagramEditPart.getViewer();
if(viewer != null){
IStructuredSelection selection= (IStructuredSelection) viewer.getSelection();
Object ep = selection.getFirstElement();
final IStructuredSelection selection= (IStructuredSelection) viewer.getSelection();
final Object ep = selection.getFirstElement();
if (ep instanceof IGraphicalEditPart){
EObject element = ((IGraphicalEditPart) ep).resolveSemanticElement();
final EObject element = ((IGraphicalEditPart) ep).resolveSemanticElement();
if (element !=null){
Object selected = ((IStructuredSelection) filteredTree.getViewer().getSelection()).getFirstElement();
final Object selected = ((IStructuredSelection) filteredTree.getViewer().getSelection()).getFirstElement();
if(selected != null && selected instanceof EObject){
IGraphicalEditPart foundEP = findEditPartFor((EObject) selected);
final IGraphicalEditPart foundEP = findEditPartFor((EObject) selected);
if(!foundEP.equals(ep)){
filteredTree.getViewer().setSelection(new StructuredSelection(element));
}
......@@ -221,9 +222,10 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
* @see org.eclipse.gef.EditPartViewer#findObjectAtExcluding(Point,
* Collection, EditPartViewer.Conditional)
*/
@Override
@SuppressWarnings("rawtypes")
public EditPart findObjectAtExcluding(Point pt, Collection exclude,
Conditional condition) {
public EditPart findObjectAtExcluding(final Point pt, final Collection exclude,
final Conditional condition) {
return null;
}
......@@ -249,20 +251,10 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
filteredTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
public void selectionChanged(final SelectionChangedEvent event) {
handleTreeSelection(tree);
}
});
// tree.addSelectionListener(new SelectionListener() {
// public void widgetSelected(SelectionEvent e) {
// // handleTreeSelection(tree);
// }
//
//
// public void widgetDefaultSelected(SelectionEvent e) {
// widgetSelected(e);
// }
// });
super.hookControl();
}
......@@ -276,7 +268,7 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
* @see org.eclipse.gef.ui.parts.AbstractEditPartViewer#reveal(org.eclipse.gef.EditPart)
*/
@Override
public void reveal(EditPart part) {}
public void reveal(final EditPart part) {}
/**
* Unhooks a control so that it can be reset. This method deactivates the
......@@ -301,15 +293,15 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
super.unhookControl();
}
protected void scrollDiagram(IGraphicalEditPart ep) {
org.eclipse.draw2d.geometry.Rectangle bounds = ep.getFigure().getBounds().getCopy();
protected void scrollDiagram(final IGraphicalEditPart ep) {
final org.eclipse.draw2d.geometry.Rectangle bounds = ep.getFigure().getBounds().getCopy();
//Get the absolute coordinate
IFigure referenceFigure = ep.getFigure() ;
final IFigure referenceFigure = ep.getFigure() ;
referenceFigure.translateToAbsolute(bounds) ;
IFigure parentFigure = referenceFigure.getParent();
while( parentFigure != null ) {
if(parentFigure instanceof Viewport) {
Viewport viewport = (Viewport)parentFigure;
final Viewport viewport = (Viewport)parentFigure;
bounds.translate(
viewport.getHorizontalRangeModel().getValue(),
viewport.getVerticalRangeModel().getValue());
......@@ -319,18 +311,18 @@ public abstract class BonitaTreeViewer extends AbstractEditPartViewer implements
parentFigure = parentFigure.getParent();
}
}
Point loc = bounds.getLocation() ;
Scrollable f = diagramEditPart.getScrollableControl() ;
((FigureCanvas)f).scrollTo(loc.x - (f.getBounds().width /2) , loc.y - (f.getBounds().height /2)) ;
final Point loc = bounds.getLocation() ;
final Scrollable f = diagramEditPart.getScrollableControl() ;
((FigureCanvas)f).scrollTo(loc.x - f.getBounds().width /2 , loc.y - f.getBounds().height /2) ;
}
@Override
public void setRootEditPart(RootEditPart editpart) {
public void setRootEditPart(final RootEditPart editpart) {
//super.setRootEditPart(editpart);
}
@Override
public void setContents(EditPart editpart) {
public void setContents(final EditPart editpart) {
}
......
......@@ -29,71 +29,71 @@ import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
public final class AutomaticSwitchPerspectivePartListener implements IPartListener {
private boolean isSwitching;
private boolean isSwitching;
@Override
public void partActivated(MPart part) {
// if(!isSwitching){
// isSwitching = true;
// try{
// if (part.getElementId().equals("org.eclipse.e4.ui.compatibility.editor")) {
// String activePerspective = getActivePerspectiveId(part);
// final String id = BonitaPerspectivesUtils.getPerspectiveId(((CompatibilityEditor) part.getObject()).getEditor());
// if (id != null && !id.equals(activePerspective)) {
// BonitaPerspectivesUtils.switchToPerspective(id);
// }
// }
// }finally{
// isSwitching = false;
// }
// }
}
@Override
public void partActivated(final MPart part) {
// if(!isSwitching){
// isSwitching = true;
// try{
// if (part.getElementId().equals("org.eclipse.e4.ui.compatibility.editor")) {
// String activePerspective = getActivePerspectiveId(part);
// final String id = BonitaPerspectivesUtils.getPerspectiveId(((CompatibilityEditor) part.getObject()).getEditor());
// if (id != null && !id.equals(activePerspective)) {
// BonitaPerspectivesUtils.switchToPerspective(id);
// }
// }
// }finally{
// isSwitching = false;
// }
// }
}
@Override
public void partBroughtToTop(MPart part) {
@Override
public void partBroughtToTop(final MPart part) {
}
}
@Override
public void partDeactivated(MPart part) {
@Override
public void partDeactivated(final MPart part) {
}
}
@Override
public void partHidden(MPart part) {
@Override
public void partHidden(final MPart part) {
}
}
@Override
public void partVisible(MPart part) {
if(!isSwitching){
isSwitching = true;
try{
if (part.getElementId().equals("org.eclipse.e4.ui.compatibility.editor")) {
if(PlatformUtil.isIntroOpen()){
PlatformUtil.closeIntro();
}
String activePerspective = getActivePerspectiveId(part);
String id = BonitaPerspectivesUtils.getPerspectiveId(((CompatibilityEditor) part.getObject()).getEditor());
if (id != null && !id.equals(activePerspective)) {
BonitaPerspectivesUtils.switchToPerspective(id);
}
}
}finally{
isSwitching = false;
}
}
}
@Override
public void partVisible(final MPart part) {
if(!isSwitching){
isSwitching = true;
try{
if (part.getElementId().equals("org.eclipse.e4.ui.compatibility.editor")) {
if(PlatformUtil.isIntroOpen()){
PlatformUtil.closeIntro();
}
final String activePerspective = getActivePerspectiveId(part);
final String id = BonitaPerspectivesUtils.getPerspectiveId(((CompatibilityEditor) part.getObject()).getEditor());
if (id != null && !id.equals(activePerspective)) {
BonitaPerspectivesUtils.switchToPerspective(id);
}
}
}finally{
isSwitching = false;
}
}
}
protected String getActivePerspectiveId(MPart part) {
EModelService service = part.getContext().get(EModelService.class);
MWindow window = service.getTopLevelWindowFor(part);
MPerspectiveStack pStack = (MPerspectiveStack) service.find("PerspectiveStack", window);
MPerspective selectedElement = pStack.getSelectedElement();
String activePerspective =null;
if(selectedElement != null){
activePerspective = selectedElement.getElementId();
}
return activePerspective;
}
protected String getActivePerspectiveId(final MPart part) {
final EModelService service = part.getContext().get(EModelService.class);
final MWindow window = service.getTopLevelWindowFor(part);
final MPerspectiveStack pStack = (MPerspectiveStack) service.find("PerspectiveStack", window);
final MPerspective selectedElement = pStack.getSelectedElement();
String activePerspective =null;
if(selectedElement != null){
activePerspective = selectedElement.getElementId();
}
return activePerspective;
}
}
\ No newline at end of file
......@@ -27,9 +27,6 @@ import org.bonitasoft.studio.common.extension.BonitaStudioExtensionRegistryManag
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPerspectiveDescriptor;
......@@ -38,7 +35,6 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.UIJob;
/**
* @author Baptiste Mesta
......@@ -48,157 +44,158 @@ import org.eclipse.ui.progress.UIJob;
*/
public class BonitaPerspectivesUtils {
private static final String VIEWS_EXTENSION_POINT = "org.bonitasoft.studio.application.PropertiesView";
private static final String PERSPECTIVES_EXTENSION_POINT = "org.eclipse.ui.perspectives";
private static List<String> contributedView;
private static List<String> allPropertiesViews;
private static Map<String, List<String>> contributedViewMap;
private static List<AbstractPerspectiveFactory> contributedPerspectives;
/**
* @return
*/
public static List<String> getContributedPropertiesViews() {
if (contributedView == null) {
contributedViewMap = new HashMap<String, List<String>>();
contributedView = new ArrayList<String>();
IConfigurationElement[] extensions = BonitaStudioExtensionRegistryManager.getInstance().getConfigurationElements(VIEWS_EXTENSION_POINT);
for (IConfigurationElement extension : extensions) {
try {
String viewId = extension.getAttribute("ViewId");
String perspectiveId = extension.getAttribute("perspectiveID");
contributedView.add(viewId);
List<String> list = contributedViewMap.get(perspectiveId);
if (list == null) {
list = new ArrayList<String>();
contributedViewMap.put(perspectiveId, list);
}
list.add(viewId);
} catch (Exception ex) {
BonitaStudioLog.error(ex);
}
}
}
return contributedView;
}
public static List<String> getContributedPropertiesViews(String perspectiveId) {
if (contributedViewMap == null) {
getContributedPropertiesViews();
}
List<String> list = contributedViewMap.get(perspectiveId);
if(list != null){
return list;
}else{
return Collections.emptyList();
}
}
public static List<String> getAllPropertiesViews() {
if (allPropertiesViews == null) {
allPropertiesViews = new ArrayList<String>();
allPropertiesViews.addAll(getContributedPropertiesViews());
allPropertiesViews.add("org.bonitasoft.studio.views.properties.process.general");
allPropertiesViews.add("org.bonitasoft.studio.views.properties.application");
allPropertiesViews.add("org.bonitasoft.studio.views.properties.form.general");
allPropertiesViews.add("org.bonitasoft.studio.views.properties.form.appearance");
allPropertiesViews.add("org.bonitasoft.studio.views.properties.process.appearance");
allPropertiesViews.add("org.bonitasoft.studio.bpmn.palette_view");
allPropertiesViews.add("org.bonitasoft.studio.form.palette_view");
}
return allPropertiesViews;
}
/**
* Switch to the perspective with id given as parameter
* @param perspectiveID
*/
public static synchronized void switchToPerspective(final String perspectiveID){
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window != null) {
final IWorkbenchPage activePage = window.getActivePage();
if (activePage != null) {
final IPerspectiveDescriptor activePerspective = activePage.getPerspective();
if (activePerspective == null || !activePerspective.getId().equals(perspectiveID)) {
IPerspectiveRegistry registry = workbench.getPerspectiveRegistry();
IWorkbenchPage page = window.getActivePage();
IPerspectiveDescriptor desc = registry.findPerspectiveWithId(perspectiveID);
page.setPerspective(desc);
UIJob job = new UIJob("changePerspective") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
if(activePage.getEditorReferences().length == 0){
PlatformUtil.openIntro();
}else{
PlatformUtil.closeIntro();
}
}
});
return Status.OK_STATUS;
}
};
job.setSystem(true);
job.schedule();
}
}
}
}
/**
* @param perspectiveID
* @return if the active perspective is the one with the ID perspectiveID
*/
public static boolean isPerspectiveWithIDActive(String perspectiveID){
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if(activeWorkbenchWindow != null){
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if(activePage != null){
IPerspectiveDescriptor perspective = activePage.getPerspective();
if(perspective != null){
return perspective.getId().equals(perspectiveID);
}
}
}
return false;
}
/**
* @param part
* @return
*/
public static String getPerspectiveId(IEditorPart part) {
if (contributedPerspectives == null) {
initializePerspectives();
}
for (AbstractPerspectiveFactory perspectiveFactory : contributedPerspectives) {
if(perspectiveFactory.isRelevantFor(part)){
return perspectiveFactory.getID();
}
}
return null;
}
public static void initializePerspectives() {
contributedPerspectives = new ArrayList<AbstractPerspectiveFactory>();
IConfigurationElement[] extensions = BonitaStudioExtensionRegistryManager.getInstance().getConfigurationElements(PERSPECTIVES_EXTENSION_POINT);
for (IConfigurationElement extension : extensions) {
try {
Object perspectiveFactory = extension.createExecutableExtension("class");
if(perspectiveFactory instanceof AbstractPerspectiveFactory){
contributedPerspectives.add((AbstractPerspectiveFactory) perspectiveFactory);
}
} catch (Exception ex) {
BonitaStudioLog.error(ex);
}
}
}
private static final String VIEWS_EXTENSION_POINT = "org.bonitasoft.studio.application.PropertiesView";
private static final String PERSPECTIVES_EXTENSION_POINT = "org.eclipse.ui.perspectives";
private static List<String> contributedView;
private static List<String> allPropertiesViews;
private static Map<String, List<String>> contributedViewMap;
private static List<AbstractPerspectiveFactory> contributedPerspectives;
/**
* @return
*/
public static List<String> getContributedPropertiesViews() {
if (contributedView == null) {
contributedViewMap = new HashMap<String, List<String>>();
contributedView = new ArrayList<String>();
final IConfigurationElement[] extensions = BonitaStudioExtensionRegistryManager.getInstance().getConfigurationElements(VIEWS_EXTENSION_POINT);
for (final IConfigurationElement extension : extensions) {
try {
final String viewId = extension.getAttribute("ViewId");
final String perspectiveId = extension.getAttribute("perspectiveID");
contributedView.add(viewId);
List<String> list = contributedViewMap.get(perspectiveId);
if (list == null) {
list = new ArrayList<String>();
contributedViewMap.put(perspectiveId, list);
}
list.add(viewId);
} catch (final Exception ex) {
BonitaStudioLog.error(ex);
}
}
}
return contributedView;
}
public static List<String> getContributedPropertiesViews(final String perspectiveId) {
if (contributedViewMap == null) {
getContributedPropertiesViews();
}
final List<String> list = contributedViewMap.get(perspectiveId);
if(list != null){
return list;
}else{
return Collections.emptyList();
}
}
public static List<String> getAllPropertiesViews() {
if (allPropertiesViews == null) {
allPropertiesViews = new ArrayList<String>();
allPropertiesViews.addAll(getContributedPropertiesViews());
allPropertiesViews.add("org.bonitasoft.studio.views.properties.process.general");
allPropertiesViews.add("org.bonitasoft.studio.views.properties.application");