Ejemplo n.º 1
0
  /**
   * Updates the problems indication with the information described in the specified diagnostic.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  protected void updateProblemIndication() {
    if (updateProblemIndication) {
      BasicDiagnostic diagnostic =
          new BasicDiagnostic(
              Diagnostic.OK,
              "org.eclipse.buckminster.rmap.editor",
              0,
              null,
              new Object[] {editingDomain.getResourceSet()});
      for (Diagnostic childDiagnostic : resourceToDiagnosticMap.values()) {
        if (childDiagnostic.getSeverity() != Diagnostic.OK) {
          diagnostic.add(childDiagnostic);
        }
      }

      int lastEditorPage = getPageCount() - 1;
      if (lastEditorPage >= 0 && getEditor(lastEditorPage) instanceof ProblemEditorPart) {
        ((ProblemEditorPart) getEditor(lastEditorPage)).setDiagnostic(diagnostic);
        if (diagnostic.getSeverity() != Diagnostic.OK) {
          setActivePage(lastEditorPage);
        }
      } else if (diagnostic.getSeverity() != Diagnostic.OK) {
        ProblemEditorPart problemEditorPart = new ProblemEditorPart();
        problemEditorPart.setDiagnostic(diagnostic);
        problemEditorPart.setMarkerHelper(markerHelper);
        try {
          addPage(++lastEditorPage, problemEditorPart, getEditorInput());
          setPageText(lastEditorPage, problemEditorPart.getPartName());
          setActivePage(lastEditorPage);
          showTabs();
        } catch (PartInitException exception) {
          RmapEditorPlugin.INSTANCE.log(exception);
        }
      }

      if (markerHelper.hasMarkers(editingDomain.getResourceSet())) {
        markerHelper.deleteMarkers(editingDomain.getResourceSet());
        if (diagnostic.getSeverity() != Diagnostic.OK) {
          try {
            markerHelper.createMarkers(diagnostic);
          } catch (CoreException exception) {
            RmapEditorPlugin.INSTANCE.log(exception);
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * This is for implementing {@link IEditorPart} and simply saves the model file.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  @Override
  public void doSave(IProgressMonitor progressMonitor) {
    // Save only resources that have actually changed.
    //
    final Map<Object, Object> saveOptions = new HashMap<Object, Object>();
    saveOptions.put(
        Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);

    // Do the work within an operation because this is a long running
    // activity that modifies the workbench.
    //
    WorkspaceModifyOperation operation =
        new WorkspaceModifyOperation() {
          // This is the method that gets invoked when the operation runs.
          //
          @Override
          public void execute(IProgressMonitor monitor) {
            // Save the resources to the file system.
            //
            boolean first = true;
            for (Resource resource : editingDomain.getResourceSet().getResources()) {
              if ((first || !resource.getContents().isEmpty() || isPersisted(resource))
                  && !editingDomain.isReadOnly(resource)) {
                try {
                  long timeStamp = resource.getTimeStamp();
                  resource.save(saveOptions);
                  if (resource.getTimeStamp() != timeStamp) {
                    savedResources.add(resource);
                  }
                } catch (Exception exception) {
                  resourceToDiagnosticMap.put(
                      resource, analyzeResourceProblems(resource, exception));
                }
                first = false;
              }
            }
          }
        };

    updateProblemIndication = false;
    try {
      // This runs the options, and shows progress.
      //
      new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);

      // Refresh the necessary state.
      //
      ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone();
      firePropertyChange(IEditorPart.PROP_DIRTY);
    } catch (Exception exception) {
      // Something went wrong that shouldn't.
      //
      RmapEditorPlugin.INSTANCE.log(exception);
    }
    updateProblemIndication = true;
    updateProblemIndication();
  }
Ejemplo n.º 3
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 @Override
 public void gotoMarker(IMarker marker) {
   try {
     if (marker.getType().equals(EValidator.MARKER)) {
       String uriAttribute = marker.getAttribute(EValidator.URI_ATTRIBUTE, null);
       if (uriAttribute != null) {
         URI uri = URI.createURI(uriAttribute);
         EObject eObject = editingDomain.getResourceSet().getEObject(uri, true);
         if (eObject != null) {
           setSelectionToViewer(Collections.singleton(editingDomain.getWrapper(eObject)));
         }
       }
     }
   } catch (CoreException exception) {
     RmapEditorPlugin.INSTANCE.log(exception);
   }
 }
Ejemplo n.º 4
0
        @Override
        public void resourceChanged(IResourceChangeEvent event) {
          IResourceDelta delta = event.getDelta();
          try {
            class ResourceDeltaVisitor implements IResourceDeltaVisitor {
              protected ResourceSet resourceSet = editingDomain.getResourceSet();
              protected Collection<Resource> changedResources = new ArrayList<Resource>();
              protected Collection<Resource> removedResources = new ArrayList<Resource>();

              public Collection<Resource> getChangedResources() {
                return changedResources;
              }

              public Collection<Resource> getRemovedResources() {
                return removedResources;
              }

              @Override
              public boolean visit(IResourceDelta delta) {
                if (delta.getResource().getType() == IResource.FILE) {
                  if (delta.getKind() == IResourceDelta.REMOVED
                      || delta.getKind() == IResourceDelta.CHANGED
                          && delta.getFlags() != IResourceDelta.MARKERS) {
                    Resource resource =
                        resourceSet.getResource(
                            URI.createPlatformResourceURI(delta.getFullPath().toString(), true),
                            false);
                    if (resource != null) {
                      if (delta.getKind() == IResourceDelta.REMOVED) {
                        removedResources.add(resource);
                      } else if (!savedResources.remove(resource)) {
                        changedResources.add(resource);
                      }
                    }
                  }
                }

                return true;
              }
            }

            final ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
            delta.accept(visitor);

            if (!visitor.getRemovedResources().isEmpty()) {
              getSite()
                  .getShell()
                  .getDisplay()
                  .asyncExec(
                      new Runnable() {
                        @Override
                        public void run() {
                          removedResources.addAll(visitor.getRemovedResources());
                          if (!isDirty()) {
                            getSite().getPage().closeEditor(RmapEditor.this, false);
                          }
                        }
                      });
            }

            if (!visitor.getChangedResources().isEmpty()) {
              getSite()
                  .getShell()
                  .getDisplay()
                  .asyncExec(
                      new Runnable() {
                        @Override
                        public void run() {
                          changedResources.addAll(visitor.getChangedResources());
                          if (getSite().getPage().getActiveEditor() == RmapEditor.this) {
                            handleActivate();
                          }
                        }
                      });
            }
          } catch (CoreException exception) {
            RmapEditorPlugin.INSTANCE.log(exception);
          }
        }
Ejemplo n.º 5
0
 /**
  * This looks up a string in plugin.properties, making a substitution.
  * <!--
  * begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 private static String getString(String key, Object s1) {
   return RmapEditorPlugin.INSTANCE.getString(key, new Object[] {s1});
 }
Ejemplo n.º 6
0
 /**
  * This looks up a string in the plugin's plugin.properties file.
  * <!--
  * begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 private static String getString(String key) {
   return RmapEditorPlugin.INSTANCE.getString(key);
 }