/** * This is the method called to load a resource into the editing domain's resource set based on * the editor's input. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public void createModel() { // I assume that the input is a file object. // IFileEditorInput modelFile = (IFileEditorInput) getEditorInput(); try { // Load the resource through the editing domain. // editingDomain.loadResource( URI.createPlatformResourceURI(modelFile.getFile().getFullPath().toString()).toString()); } catch (Exception exception) { GenfwEditorPlugin.INSTANCE.log(exception); } }
/** * * <!-- 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) { GenfwEditorPlugin.INSTANCE.log(exception); } }
/** * Handles what to do with changed resources on activation. * * @generated */ protected void handleChangedResources() { if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict())) { editingDomain.getCommandStack().flush(); for (Iterator i = changedResources.iterator(); i.hasNext(); ) { Resource resource = (Resource) i.next(); if (resource.isLoaded()) { resource.unload(); try { resource.load(Collections.EMPTY_MAP); } catch (IOException exception) { GenfwEditorPlugin.INSTANCE.log(exception); } } } } }
/** * This is for implementing {@link IEditorPart} and simply saves the model file. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public void doSave(IProgressMonitor progressMonitor) { // 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. // public void execute(IProgressMonitor monitor) { try { // Save the resources to the file system. // boolean first = true; for (Iterator i = editingDomain.getResourceSet().getResources().iterator(); i.hasNext(); ) { Resource resource = (Resource) i.next(); if ((first || !resource.getContents().isEmpty()) && !editingDomain.isReadOnly(resource)) { savedResources.add(resource); resource.save(Collections.EMPTY_MAP); } first = false; } } catch (Exception exception) { GenfwEditorPlugin.INSTANCE.log(exception); } } }; 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. // GenfwEditorPlugin.INSTANCE.log(exception); } }
public void resourceChanged(IResourceChangeEvent event) { // Only listening to these. // if (event.getType() == IResourceDelta.POST_CHANGE) { IResourceDelta delta = event.getDelta(); try { class ResourceDeltaVisitor implements IResourceDeltaVisitor { protected ResourceSet resourceSet = editingDomain.getResourceSet(); protected Collection changedResources = new ArrayList(); protected Collection removedResources = new ArrayList(); public boolean visit(IResourceDelta delta) { if (delta.getFlags() != IResourceDelta.MARKERS && delta.getResource().getType() == IResource.FILE) { if ((delta.getKind() & (IResourceDelta.CHANGED | IResourceDelta.REMOVED)) != 0) { Resource resource = resourceSet.getResource( URI.createURI(delta.getFullPath().toString()), false); if (resource != null) { if ((delta.getKind() & IResourceDelta.REMOVED) != 0) { removedResources.add(resource); } else { changedResources.add(resource); } } } } return true; } public Collection getChangedResources() { return changedResources; } public Collection getRemovedResources() { return removedResources; } } ResourceDeltaVisitor visitor = new ResourceDeltaVisitor(); delta.accept(visitor); if (!visitor.getRemovedResources().isEmpty()) { removedResources.addAll(visitor.getRemovedResources()); if (!isDirty()) { getSite() .getShell() .getDisplay() .asyncExec( new Runnable() { public void run() { getSite().getPage().closeEditor(GenfwEditor.this, false); GenfwEditor.this.dispose(); } }); } } if (!visitor.getChangedResources().isEmpty()) { changedResources.addAll(visitor.getChangedResources()); } } catch (CoreException exception) { GenfwEditorPlugin.INSTANCE.log(exception); } } }