/** * 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.dltk.javascript.core.editor", //$NON-NLS-1$ 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) { ReferencesEditorPlugin.INSTANCE.log(exception); } } if (markerHelper.hasMarkers(editingDomain.getResourceSet())) { markerHelper.deleteMarkers(editingDomain.getResourceSet()); if (diagnostic.getSeverity() != Diagnostic.OK) { try { markerHelper.createMarkers(diagnostic); } catch (CoreException exception) { ReferencesEditorPlugin.INSTANCE.log(exception); } } } } }
/** * 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. // ReferencesEditorPlugin.INSTANCE.log(exception); } updateProblemIndication = true; updateProblemIndication(); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ 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) { ReferencesEditorPlugin.INSTANCE.log(exception); } }
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 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; } public Collection<Resource> getChangedResources() { return changedResources; } public Collection<Resource> getRemovedResources() { return removedResources; } } final ResourceDeltaVisitor visitor = new ResourceDeltaVisitor(); delta.accept(visitor); if (!visitor.getRemovedResources().isEmpty()) { getSite() .getShell() .getDisplay() .asyncExec( new Runnable() { public void run() { removedResources.addAll(visitor.getRemovedResources()); if (!isDirty()) { getSite().getPage().closeEditor(TypeInfoModelEditor.this, false); } } }); } if (!visitor.getChangedResources().isEmpty()) { getSite() .getShell() .getDisplay() .asyncExec( new Runnable() { public void run() { changedResources.addAll(visitor.getChangedResources()); if (getSite().getPage().getActiveEditor() == TypeInfoModelEditor.this) { handleActivate(); } } }); } } catch (CoreException exception) { ReferencesEditorPlugin.INSTANCE.log(exception); } }