示例#1
0
 /**
  * Creates a code folding manager to handle the <code>
  * org.eclipse.jface.text.source.projection.ProjectionAnnotation</code>.
  *
  * @param sourceViewer the source viewer to calculate the element lines
  */
 public TestmodelCodeFoldingManager(
     org.eclipse.jface.text.source.projection.ProjectionViewer sourceViewer,
     edu.ustb.sei.mde.testing.testdefinition.resource.testmodel.ui.TestmodelEditor textEditor) {
   this.projectionAnnotationModel = sourceViewer.getProjectionAnnotationModel();
   this.sourceViewer = sourceViewer;
   this.editor = textEditor;
   addCloseListener(textEditor);
   try {
     restoreCodeFoldingStateFromFile(editor.getResource().getURI().toString());
   } catch (Exception e) {
     calculatePositions();
   }
 }
示例#2
0
 public void partClosed(org.eclipse.ui.IWorkbenchPartReference partRef) {
   if (partRef.isDirty()) {
     return;
   }
   org.eclipse.ui.IWorkbenchPart workbenchPart = partRef.getPart(false);
   if (workbenchPart
       instanceof
       edu.ustb.sei.mde.testing.testdefinition.resource.testmodel.ui.TestmodelEditor) {
     edu.ustb.sei.mde.testing.testdefinition.resource.testmodel.ui.TestmodelEditor editor =
         (edu.ustb.sei.mde.testing.testdefinition.resource.testmodel.ui.TestmodelEditor)
             workbenchPart;
     org.eclipse.emf.ecore.resource.Resource editorResource = editor.getResource();
     if (editorResource == null) {
       return;
     }
     String uri = editorResource.getURI().toString();
     org.eclipse.emf.ecore.resource.Resource thisEditorResource = this.editor.getResource();
     org.eclipse.emf.common.util.URI thisEditorResourceURI = thisEditorResource.getURI();
     if (uri.equals(thisEditorResourceURI.toString())) {
       saveCodeFoldingStateFile(uri);
       editor.getSite().getPage().removePartListener(this);
     }
   }
 }
示例#3
0
 protected void calculatePositions() {
   edu.ustb.sei.mde.testing.testdefinition.resource.testmodel.ITestmodelTextResource textResource =
       (edu.ustb.sei.mde.testing.testdefinition.resource.testmodel.ITestmodelTextResource)
           editor.getResource();
   org.eclipse.jface.text.IDocument document = sourceViewer.getDocument();
   if (textResource == null || document == null) {
     return;
   }
   org.eclipse.emf.common.util.EList<?> errorList = textResource.getErrors();
   if (errorList != null && errorList.size() > 0) {
     return;
   }
   final java.util.List<org.eclipse.jface.text.Position> positions =
       new java.util.ArrayList<org.eclipse.jface.text.Position>();
   edu.ustb.sei.mde.testing.testdefinition.resource.testmodel.ITestmodelLocationMap locationMap =
       textResource.getLocationMap();
   org.eclipse.emf.ecore.EClass[] foldableClasses =
       textResource.getMetaInformation().getFoldableClasses();
   if (foldableClasses == null) {
     return;
   }
   if (foldableClasses.length < 1) {
     return;
   }
   java.util.List<org.eclipse.emf.ecore.EObject> contents = textResource.getContents();
   org.eclipse.emf.ecore.EObject[] contentArray =
       contents.toArray(new org.eclipse.emf.ecore.EObject[0]);
   java.util.List<org.eclipse.emf.ecore.EObject> allContents = getAllContents(contentArray);
   for (org.eclipse.emf.ecore.EObject nextObject : allContents) {
     boolean isFoldable = false;
     for (org.eclipse.emf.ecore.EClass eClass : foldableClasses) {
       if (nextObject.eClass().equals(eClass)) {
         isFoldable = true;
         break;
       }
     }
     if (!isFoldable) {
       continue;
     }
     int offset = locationMap.getCharStart(nextObject);
     int length = locationMap.getCharEnd(nextObject) + 1 - offset;
     try {
       int lines = document.getNumberOfLines(offset, length);
       if (lines < 2) {
         continue;
       }
     } catch (org.eclipse.jface.text.BadLocationException e) {
       continue;
     }
     length = getOffsetOfNextLine(document, length + offset) - offset;
     if (offset >= 0 && length > 0) {
       positions.add(new org.eclipse.jface.text.Position(offset, length));
     }
   }
   org.eclipse.swt.widgets.Display.getDefault()
       .asyncExec(
           new Runnable() {
             public void run() {
               updateCodefolding(positions);
             }
           });
 }