Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add EPartServiceExt.closeUri method for closing opened editors

  • Loading branch information...
commit 13a6875ef98739bcd76290471c8463a77f05c974 1 parent ead4060
@semanticsoft authored
View
84 org.semanticsoft.e4extension/src/org/semanticsoft/e4extension/impl/PartServiceExtImpl.java
@@ -172,38 +172,35 @@ public MInputPart openUri(String inputUri)
return this.openUri(null, inputUri);
}
- private MInputPart ensurePartAdded(MWindow window, MElementContainer<?> area, EditorPartDescriptor editorPartDescriptor, String inputUri)
+ @Override
+ public void closeUri(String inputUri, boolean saveBeforeClose)
{
- MPerspectiveStack stack = null;
- for (MUIElement e : window.getChildren()) {
- if (e instanceof MPerspectiveStack)
- {
- stack = (MPerspectiveStack) e;
- break;
- }
- }
-
- MPerspective persp = stack != null ? stack.getSelectedElement() : null;
-
- MElementContainer<?> container = persp != null ? persp : window;
+ MInputPart part = findPart(getWindow(), inputUri);
- List<MPart> parts = modelService.findElements(container, null, MPart.class, null,
- EModelService.OUTSIDE_PERSPECTIVE | EModelService.IN_ACTIVE_PERSPECTIVE
- | EModelService.IN_SHARED_AREA);
+ if (part == null)
+ return;
- MInputPart part = null;
- for (MPart p : parts)
+ if (saveBeforeClose)
{
- if (p instanceof MInputPart)
- {
- String _inputUri = ((MInputPart) p).getInputURI();
- if (inputUri.equals(_inputUri))
- {
- part = (MInputPart) p;
- break;
- }
+ IEclipseContext partContext = part.getContext();
+ if (partContext == null)
+ partContext = modelService.getContainingContext(part);
+
+ // Allow closes to be 'canceled'
+ EPartService partService = (EPartService) partContext.get(EPartService.class.getName());
+ if (partService.savePart(part, true)) {
+ partService.hidePart(part, true);
}
}
+ else
+ {
+ partService.hidePart(part, true);
+ }
+ }
+
+ private MInputPart ensurePartAdded(MWindow window, MElementContainer<?> area, EditorPartDescriptor editorPartDescriptor, String inputUri)
+ {
+ MInputPart part = findPart(window, inputUri);
if (part == null)
{//else we create new part and add it with specified logic
@@ -232,6 +229,41 @@ private MInputPart ensurePartAdded(MWindow window, MElementContainer<?> area, Ed
return part;
}
+
+ private MInputPart findPart(MWindow window, String inputUri)
+ {
+ MPerspectiveStack stack = null;
+ for (MUIElement e : window.getChildren()) {
+ if (e instanceof MPerspectiveStack)
+ {
+ stack = (MPerspectiveStack) e;
+ break;
+ }
+ }
+
+ MPerspective persp = stack != null ? stack.getSelectedElement() : null;
+
+ MElementContainer<?> container = persp != null ? persp : window;
+
+ List<MPart> parts = modelService.findElements(container, null, MPart.class, null,
+ EModelService.OUTSIDE_PERSPECTIVE | EModelService.IN_ACTIVE_PERSPECTIVE
+ | EModelService.IN_SHARED_AREA);
+
+ MInputPart part = null;
+ for (MPart p : parts)
+ {
+ if (p instanceof MInputPart)
+ {
+ String _inputUri = ((MInputPart) p).getInputURI();
+ if (inputUri.equals(_inputUri))
+ {
+ part = (MInputPart) p;
+ break;
+ }
+ }
+ }
+ return part;
+ }
private MWindow getWindow() {
if (application.getSelectedElement() != null)
View
4 org.semanticsoft.e4extension/src/org/semanticsoft/e4extension/service/EPartServiceExt.java
@@ -60,10 +60,12 @@
*/
MInputPart openUri(MElementContainer<?> area, String inputUri);
+ void closeUri(String inputUri, boolean saveBeforeClose);
+
/**
* Fixed method EPartService.showPart. Current method search any opened shared part and if allowMultiples == false (default) it
* create placeholder on this part rather creating new. The differences from original showPart is that it search shared part in any perspective,
- * the orginal showPart search shared part in active perspective. I can not say is this bug or general contract of this method...
+ * the original showPart search shared part in active perspective. I can not say is this bug or general contract of this method...
* @param id
* @param partState
* @return
Please sign in to comment.
Something went wrong with that request. Please try again.