Skip to content
Snippets Groups Projects
Commit 03b9414c authored by Lukas Ladenberger's avatar Lukas Ladenberger
Browse files

working on multiview support

parent 2c6002fd
No related branches found
No related tags found
No related merge requests found
Showing
with 243 additions and 141 deletions
......@@ -722,4 +722,10 @@
</control>
</include>
</extension>
<extension
point="org.eclipse.ui.startup">
<startup
class="de.bmotionstudio.gef.editor.BMotionStartup">
</startup>
</extension>
</plugin>
......@@ -46,13 +46,14 @@ public class BMSPerspectiveFactory implements IPerspectiveFactory {
IFolderLayout top = layout.createFolder("bottom1", IPageLayout.BOTTOM,
0.20f, IPageLayout.ID_EDITOR_AREA);
top.addPlaceholder(VisualizationViewPart.ID + ":*");
layout.getViewLayout(VisualizationViewPart.ID).setCloseable(false);
// Properties view + observer view + control panel
IFolderLayout bottom = layout.createFolder("bottom2",
IPageLayout.BOTTOM, 0.65f, "bottom1");
bottom.addView(ControlPanel.ID);
bottom.addView(IPageLayout.ID_PROP_SHEET);
bottom.addView(ObserverView.ID);
bottom.addView(ControlPanel.ID);
}
......
......@@ -94,6 +94,7 @@ public class BMotionEditorPlugin extends AbstractUIPlugin {
super.stop(context);
}
/**
* Returns the shared instance
*
......
package de.bmotionstudio.gef.editor;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.PlatformUI;
import de.bmotionstudio.gef.editor.util.PerspectiveUtil;
public class BMotionStartup implements IStartup {
@Override
public void earlyStartup() {
IPerspectiveRegistry perspectiveRegistry = PlatformUI.getWorkbench()
.getPerspectiveRegistry();
IPerspectiveDescriptor[] perspectives = perspectiveRegistry
.getPerspectives();
for (IPerspectiveDescriptor p : perspectives) {
if (p.getId().startsWith("BMS_"))
PerspectiveUtil.closePerspective(p);
PerspectiveUtil.deletePerspective(p);
}
}
}
package de.bmotionstudio.gef.editor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
......@@ -12,15 +8,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IExportedPreferences;
import org.eclipse.core.runtime.preferences.IPreferenceFilter;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.core.runtime.preferences.PreferenceFilterEntry;
import org.eclipse.ui.IEditorLauncher;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartSite;
......@@ -37,8 +25,6 @@ import de.bmotionstudio.gef.editor.util.PerspectiveUtil;
public class BMotionStudioLauncher implements IEditorLauncher {
private Simulation simulation;
private IFile file;
@Override
......@@ -47,9 +33,39 @@ public class BMotionStudioLauncher implements IEditorLauncher {
file = ResourcesPlugin.getWorkspace().getRoot()
.getFileForLocation(path);
if (BMotionEditorPlugin.getOpenSimulations()
.containsKey(file.getName()))
Simulation simulation = BMotionEditorPlugin.getOpenSimulations().get(
file.getName());
// final String perspectiveId = PerspectiveUtil
// .getPerspectiveIdFromFile(file);
// The simulation is already open
if (simulation != null) {
PerspectiveUtil.openPerspective(simulation);
//
// IPerspectiveDescriptor perspective = PlatformUI.getWorkbench()
// .getPerspectiveRegistry()
// .findPerspectiveWithId(perspectiveId);
//
// // Check if a perspective already exists
// if (perspective != null) {
// // If yes, just switch the perspective
// PerspectiveUtil.switchPerspective(perspective);
// } else {
//
//
// }
//
// IFile perspectiveFile = file.getProject().getFile(
// getPerspectiveFileName());
// if (perspectiveFile.exists()) {
//
// }
// PerspectiveUtil.openPerspective(simulation);
return;
}
InputStream inputStream = null;
......@@ -81,10 +97,6 @@ public class BMotionStudioLauncher implements IEditorLauncher {
.getActiveWorkbenchWindow().getActivePage();
IWorkbenchPartSite site = activePage.getActivePart().getSite();
importPerspective(file.getProject().getFile(
getPerspectiveFileName()));
openPerspective(site.getPage());
if (obj instanceof Visualization) {
simulation = new Simulation();
......@@ -108,6 +120,9 @@ public class BMotionStudioLauncher implements IEditorLauncher {
simulation.setProjectFile(file);
System.out.println("Open Perspecitve");
PerspectiveUtil.openPerspective(simulation);
for (Map.Entry<String, VisualizationView> entry : simulation
.getVisualizationViews().entrySet()) {
......@@ -116,18 +131,29 @@ public class BMotionStudioLauncher implements IEditorLauncher {
Visualization vis = visView.getVisualization();
vis.setProjectFile(file);
// String partName = visView.getPartName();
// IViewReference viewReference = site.getPage()
// .findViewReference(VisualizationViewPart.ID, secId);
IViewReference viewReference = site.getPage()
.findViewReference(VisualizationViewPart.ID, secId);
VisualizationViewPart visualizationViewPart;
// Check if view already exists
// if (viewReference != null) {
// } else {
if (viewReference != null) {
visualizationViewPart = (VisualizationViewPart) viewReference
.getPart(true);
System.out.println(" ===> Visualization found: "
+ visualizationViewPart);
} else {
// If not, create a new one
VisualizationViewPart visualizationViewPart = PerspectiveUtil
.createVisualizationViewPart(
secId, visView);
if (!visualizationViewPart.isInitialized())
visualizationViewPart = PerspectiveUtil
.createVisualizationViewPart(secId, visView);
System.out.println(" ===> Visualization created: "
+ visualizationViewPart);
}
if (visualizationViewPart != null
&& !visualizationViewPart.isInitialized()) {
System.out
.println(" ===> Visualization initialized");
visualizationViewPart.init(simulation, visView);
// }
}
}
......@@ -159,87 +185,4 @@ public class BMotionStudioLauncher implements IEditorLauncher {
}
private IPerspectiveDescriptor openPerspective(IWorkbenchPage page) {
if (page == null)
return null;
// Try to get the corresponding perspective
IPerspectiveRegistry perspectiveRegistry = page.getWorkbenchWindow()
.getWorkbench().getPerspectiveRegistry();
String perspectiveId = PerspectiveUtil.getPerspectiveIdFromFile(file);
IPerspectiveDescriptor perspective = perspectiveRegistry
.findPerspectiveWithId(perspectiveId);
// Yes --> just switch to this perspective
if (perspective != null) {
PerspectiveUtil.switchPerspective(perspective);
} else {
// No --> create a new one
IPerspectiveDescriptor originalPerspectiveDescriptor = perspectiveRegistry
.findPerspectiveWithId(BMSPerspectiveFactory.ID);
PerspectiveUtil.switchPerspective(originalPerspectiveDescriptor);
perspective = perspectiveRegistry.clonePerspective(perspectiveId,
perspectiveId, originalPerspectiveDescriptor);
// save the perspective
page.savePerspectiveAs(perspective);
}
return perspective;
}
private void importPerspective(IFile perspectiveFile) {
FileInputStream fis = null;
try {
IPreferenceFilter[] transfers = null;
transfers = new IPreferenceFilter[1];
// Only import if a perspective file exists
if (perspectiveFile.exists()) {
File exportFile = new File(perspectiveFile.getLocationURI());
fis = new FileInputStream(exportFile);
IPreferencesService service = Platform.getPreferencesService();
// service.importPreferences(fis);
IExportedPreferences prefs = service.readPreferences(fis);
transfers[0] = new IPreferenceFilter() {
public String[] getScopes() {
return new String[] { InstanceScope.SCOPE };
}
public Map<String, PreferenceFilterEntry[]> getMapping(
String scope) {
Map<String, PreferenceFilterEntry[]> map = new HashMap<String, PreferenceFilterEntry[]>();
map.put("org.eclipse.ui.workbench",
new PreferenceFilterEntry[] { new PreferenceFilterEntry(
PerspectiveUtil
.getPerspectiveIdFromFile(file)
+ "_persp") });
return map;
}
};
service.applyPreferences(prefs, transfers);
}
} catch (FileNotFoundException e) {
} catch (CoreException e) {
} finally {
try {
if (fis != null)
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private String getPerspectiveFileName() {
return file.getName().replace(".bmso", ".bmsop");
}
}
......@@ -369,6 +369,7 @@ public class VisualizationViewPart extends ViewPart implements
@Override
public void setFocus() {
container.setFocus();
}
public void init(Simulation simulation, VisualizationView visualizationView) {
......
......@@ -16,6 +16,7 @@ import org.eclipse.ui.PartInitException;
import de.bmotionstudio.gef.editor.BMotionEditorPlugin;
import de.bmotionstudio.gef.editor.BMotionStudioImage;
import de.bmotionstudio.gef.editor.VisualizationViewPart;
import de.bmotionstudio.gef.editor.model.Simulation;
import de.bmotionstudio.gef.editor.model.Visualization;
import de.bmotionstudio.gef.editor.model.VisualizationView;
......@@ -41,6 +42,8 @@ public class AddVisualizationViewAction extends Action {
Simulation simulation = (Simulation) firstElement;
PerspectiveUtil.openPerspective(simulation);
try {
String secId = UUID.randomUUID().toString();
......@@ -56,8 +59,10 @@ public class AddVisualizationViewAction extends Action {
simulation.getVisualizationViews()
.put(secId, visualizationView);
PerspectiveUtil.createVisualizationViewPart(secId,
VisualizationViewPart visualizationViewPart = PerspectiveUtil
.createVisualizationViewPart(secId,
visualizationView);
visualizationViewPart.init(simulation, visualizationView);
simulation.setDirty(true);
viewer.refresh();
......
......@@ -11,8 +11,6 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import de.bmotionstudio.gef.editor.BMotionEditorPlugin;
......@@ -38,20 +36,17 @@ public class CloseSimulationAction extends Action {
Object firstElement = sel.getFirstElement();
if (firstElement instanceof Simulation) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow()
.getActivePage();
IPerspectiveRegistry perspectiveRegistry = workbench
.getPerspectiveRegistry();
IPerspectiveRegistry perspectiveRegistry = PlatformUI
.getWorkbench().getPerspectiveRegistry();
Simulation simulation = (Simulation) firstElement;
String perspectiveId = PerspectiveUtil
.getPerspectiveIdFromFile(simulation.getProjectFile());
IPerspectiveDescriptor perspectiveDescriptor = perspectiveRegistry.findPerspectiveWithId(perspectiveId);
IPerspectiveDescriptor perspectiveDescriptor = perspectiveRegistry
.findPerspectiveWithId(perspectiveId);
if (perspectiveDescriptor != null) {
PerspectiveUtil.closePerspective(page, perspectiveDescriptor);
PerspectiveUtil.deletePerspective(page, perspectiveDescriptor);
PerspectiveUtil.closePerspective(perspectiveDescriptor);
PerspectiveUtil.deletePerspective(perspectiveDescriptor);
}
BMotionEditorPlugin.closeSimulation(simulation);
......
......@@ -8,6 +8,8 @@ import java.util.Map;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.gef.commands.CommandStackListener;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.DoubleClickEvent;
......@@ -168,11 +170,30 @@ public class ControlPanel extends ViewPart implements ISimulationListener,
treeViewer.expandAll();
}
final CloseSimulationAction closeSimulationAction = new CloseSimulationAction(
treeViewer);
final SaveSimulationAction saveSimulationAction = new SaveSimulationAction(
treeViewer);
final AddVisualizationViewAction addVisualizationViewAction = new AddVisualizationViewAction(
treeViewer);
final Separator separator = new Separator();
MenuManager manager = new MenuManager();
manager.add(new CloseSimulationAction(treeViewer));
manager.add(new SaveSimulationAction(treeViewer));
manager.add(new Separator());
manager.add(new AddVisualizationViewAction(treeViewer));
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
IStructuredSelection selection = (IStructuredSelection) treeViewer
.getSelection();
Object firstElement = selection.getFirstElement();
if (firstElement instanceof Simulation) {
manager.add(closeSimulationAction);
manager.add(saveSimulationAction);
manager.add(separator);
manager.add(addVisualizationViewAction);
}
}
});
treeViewer.getControl().setMenu(
manager.createContextMenu(treeViewer.getControl()));
......
......@@ -2,6 +2,7 @@ package de.bmotionstudio.gef.editor.util;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
......@@ -13,6 +14,7 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IExportedPreferences;
import org.eclipse.core.runtime.preferences.IPreferenceFilter;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.core.runtime.preferences.InstanceScope;
......@@ -26,6 +28,7 @@ import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
import de.bmotionstudio.gef.editor.BMSPerspectiveFactory;
import de.bmotionstudio.gef.editor.VisualizationViewPart;
import de.bmotionstudio.gef.editor.model.Simulation;
import de.bmotionstudio.gef.editor.model.VisualizationView;
......@@ -33,19 +36,17 @@ import de.prob.logging.Logger;
public class PerspectiveUtil {
public static void deletePerspective(IWorkbenchPage page,
public static void deletePerspective(
IPerspectiveDescriptor perspectiveDescriptor) {
if (perspectiveDescriptor == null || page == null)
return;
IPerspectiveRegistry perspectiveRegistry = page.getWorkbenchWindow()
.getWorkbench().getPerspectiveRegistry();
IPerspectiveRegistry perspectiveRegistry = PlatformUI.getWorkbench()
.getPerspectiveRegistry();
perspectiveRegistry.deletePerspective(perspectiveDescriptor);
}
public static void closePerspective(IWorkbenchPage page,
public static void closePerspective(
IPerspectiveDescriptor perspectiveDescriptor) {
if (perspectiveDescriptor == null || page == null)
return;
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
page.closePerspective(perspectiveDescriptor, false, true);
}
......@@ -134,6 +135,10 @@ public class PerspectiveUtil {
return "BMS_" + file.getName().replace(".bmso", "");
}
public static String getPerspectiveFileName(IFile file) {
return file.getName().replace(".bmso", ".bmsop");
}
public static VisualizationViewPart createVisualizationViewPart(
String secId, VisualizationView visualizationView)
throws PartInitException {
......@@ -146,4 +151,101 @@ public class PerspectiveUtil {
return visualizationViewPart;
}
public static void importPerspective(final IFile perspectiveFile,
final String perspectiveID) {
FileInputStream fis = null;
try {
IPreferenceFilter[] transfers = null;
transfers = new IPreferenceFilter[1];
// Only import if a perspective file exists
if (perspectiveFile.exists()) {
File exportFile = new File(perspectiveFile.getLocationURI());
fis = new FileInputStream(exportFile);
IPreferencesService service = Platform.getPreferencesService();
// service.importPreferences(fis);
IExportedPreferences prefs = service.readPreferences(fis);
transfers[0] = new IPreferenceFilter() {
public String[] getScopes() {
return new String[] { InstanceScope.SCOPE };
}
public Map<String, PreferenceFilterEntry[]> getMapping(
String scope) {
Map<String, PreferenceFilterEntry[]> map = new HashMap<String, PreferenceFilterEntry[]>();
map.put("org.eclipse.ui.workbench",
new PreferenceFilterEntry[] { new PreferenceFilterEntry(
perspectiveID + "_persp") });
return map;
}
};
service.applyPreferences(prefs, transfers);
}
} catch (FileNotFoundException e) {
} catch (CoreException e) {
} finally {
try {
if (fis != null)
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static IPerspectiveDescriptor openPerspective(Simulation simulation) {
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
// Try to get the corresponding perspective
IPerspectiveRegistry perspectiveRegistry = page.getWorkbenchWindow()
.getWorkbench().getPerspectiveRegistry();
String perspectiveId = PerspectiveUtil
.getPerspectiveIdFromFile(simulation.getProjectFile());
IPerspectiveDescriptor perspective = perspectiveRegistry
.findPerspectiveWithId(perspectiveId);
// Yes --> just switch to this perspective
if (perspective != null) {
PerspectiveUtil.switchPerspective(perspective);
} else {
// Check if a corresponding perspective file exists
IFile perspectiveFile = simulation
.getProjectFile()
.getProject()
.getFile(
PerspectiveUtil.getPerspectiveFileName(simulation
.getProjectFile()));
if (perspectiveFile.exists()) {
PerspectiveUtil.importPerspective(perspectiveFile,
perspectiveId);
perspective = perspectiveRegistry
.findPerspectiveWithId(perspectiveId);
PerspectiveUtil.switchPerspective(perspective);
} else {
// No --> create a new one
IPerspectiveDescriptor originalPerspectiveDescriptor = perspectiveRegistry
.findPerspectiveWithId(BMSPerspectiveFactory.ID);
PerspectiveUtil
.switchPerspective(originalPerspectiveDescriptor);
perspective = perspectiveRegistry.clonePerspective(
perspectiveId, perspectiveId,
originalPerspectiveDescriptor);
// save the perspective
page.savePerspectiveAs(perspective);
}
}
return perspective;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment