📄 extlibraryeditor.java
字号:
{
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 if (!savedResources.remove(resource))
{
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(EXTLibraryEditor.this, false);
EXTLibraryEditor.this.dispose();
}
});
}
}
if (!visitor.getChangedResources().isEmpty())
{
changedResources.addAll(visitor.getChangedResources());
if (getSite().getPage().getActiveEditor() == EXTLibraryEditor.this)
{
getSite().getShell().getDisplay().asyncExec
(new Runnable()
{
public void run()
{
handleActivate();
}
});
}
}
}
catch (CoreException exception)
{
EXTLibraryEditorPlugin.INSTANCE.log(exception);
}
}
}
};
/**
* Handles activation of the editor or it's associated views.
* @generated
*/
protected void handleActivate()
{
// Recompute the read only state.
//
if (editingDomain.getResourceToReadOnlyMap() != null)
{
editingDomain.getResourceToReadOnlyMap().clear();
// Refresh any actions that may become enabled or disabled.
//
setSelection(getSelection());
}
if (!removedResources.isEmpty())
{
if (handleDirtyConflict())
{
getSite().getPage().closeEditor(EXTLibraryEditor.this, false);
EXTLibraryEditor.this.dispose();
}
else
{
removedResources.clear();
changedResources.clear();
savedResources.clear();
}
}
else if (!changedResources.isEmpty())
{
changedResources.removeAll(savedResources);
handleChangedResources();
changedResources.clear();
savedResources.clear();
}
}
/**
* Handles what to do with changed resources on activation.
* @generated
*/
protected void handleChangedResources()
{
if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict()))
{
editingDomain.getCommandStack().flush();
updateProblemIndication = false;
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)
{
if (!resourceToDiagnosticMap.containsKey(resource))
{
resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception));
}
}
}
}
updateProblemIndication = true;
updateProblemIndication();
}
}
/**
* 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.emf.examples.library.editor", //$NON-NLS-1$
0,
null,
new Object [] { editingDomain.getResourceSet() });
for (Iterator i = resourceToDiagnosticMap.values().iterator(); i.hasNext(); )
{
Diagnostic childDiagnostic = (Diagnostic)i.next();
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)
{
EXTLibraryEditorPlugin.INSTANCE.log(exception);
}
}
if (markerHelper.hasMarkers(editingDomain.getResourceSet()))
{
markerHelper.deleteMarkers(editingDomain.getResourceSet());
if (diagnostic.getSeverity() != Diagnostic.OK)
{
try
{
markerHelper.createMarkers(diagnostic);
}
catch (CoreException exception)
{
EXTLibraryEditorPlugin.INSTANCE.log(exception);
}
}
}
}
}
/**
* Shows a dialog that asks if conflicting changes should be discarded.
* @generated
*/
protected boolean handleDirtyConflict()
{
return
MessageDialog.openQuestion
(getSite().getShell(),
getString("_UI_FileConflict_label"), //$NON-NLS-1$
getString("_WARN_FileConflict")); //$NON-NLS-1$
}
/**
* This creates a model editor.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EXTLibraryEditor()
{
super();
// Create an adapter factory that yields item providers.
//
List factories = new ArrayList();
factories.add(new ResourceItemProviderAdapterFactory());
factories.add(new EXTLibraryItemProviderAdapterFactory());
factories.add(new ReflectiveItemProviderAdapterFactory());
adapterFactory = new ComposedAdapterFactory(factories);
// Create the command stack that will notify this editor as commands are executed.
//
BasicCommandStack commandStack = new BasicCommandStack();
// Add a listener to set the most recent command's affected objects to be the selection of the viewer with focus.
//
commandStack.addCommandStackListener
(new CommandStackListener()
{
public void commandStackChanged(final EventObject event)
{
getContainer().getDisplay().asyncExec
(new Runnable()
{
public void run()
{
firePropertyChange(IEditorPart.PROP_DIRTY);
// Try to select the affected objects.
//
Command mostRecentCommand = ((CommandStack)event.getSource()).getMostRecentCommand();
if (mostRecentCommand != null)
{
setSelectionToViewer(mostRecentCommand.getAffectedObjects());
}
if (propertySheetPage != null && !propertySheetPage.getControl().isDisposed())
{
propertySheetPage.refresh();
}
}
});
}
});
// Create the editing domain with a special command stack.
//
editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap());
}
/**
* This is here for the listener to be able to call it.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void firePropertyChange(int action)
{
super.firePropertyChange(action);
}
/**
* This sets the selection into whichever viewer is active.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setSelectionToViewer(Collection collection)
{
final Collection theSelection = collection;
// Make sure it's okay.
//
if (theSelection != null && !theSelection.isEmpty())
{
// I don't know if this should be run this deferred
// because we might have to give the editor a chance to process the viewer update events
// and hence to update the views first.
//
//
Runnable runnable =
new Runnable()
{
public void run()
{
// Try to select the items in the current content viewer of the editor.
//
if (currentViewer != null)
{
currentViewer.setSelection(new StructuredSelection(theSelection.toArray()), true);
}
}
};
runnable.run();
}
}
/**
* This returns the editing domain as required by the {@link IEditingDomainProvider} interface.
* This is important for implementing the static methods of {@link AdapterFactoryEditingDomain}
* and for supporting {@link org.eclipse.emf.edit.ui.action.CommandAction}.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EditingDomain getEditingDomain()
{
return editingDomain;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public class ReverseAdapterFactoryContentProvider extends AdapterFactoryContentProvider
{
public ReverseAdapterFactoryContentProvider(AdapterFactory adapterFactory)
{
super(adapterFactory);
}
public Object[] getElements(Object object)
{
Object parent = super.getParent(object);
return (parent == null ? Collections.EMPTY_SET : Collections.singleton(parent)).toArray();
}
public Object[] getChildren(Object object)
{
Object parent = super.getParent(object);
return (parent == null ? Collections.EMPTY_SET : Collections.singleton(parent)).toArray();
}
public boolean hasChildren(Object object)
{
Object parent = super.getParent(object);
return parent != null;
}
public Object getParent(Object object)
{
return null;
}
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setCurrentViewerPane(ViewerPane viewerPane)
{
if (currentViewerPane != viewerPane)
{
if (currentViewerPane != null)
{
currentViewerPane.showFocus(false);
}
currentViewerPane = viewerPane;
}
setCurrentViewer(currentViewerPane.getViewer());
}
/**
* This makes sure that one content viewer, either for the current page or the outline view, if it has focus,
* is the current one.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setCurrentViewer(Viewer viewer)
{
// If it is changing...
//
if (currentViewer != viewer)
{
if (selectionChangedListener == null)
{
// Create the listener on demand.
//
selectionChangedListener =
new ISelectionChangedListener()
{
// This just notifies those things that are affected by the section.
//
public void selectionChanged(SelectionChangedEvent selectionChangedEvent)
{
setSelection(selectionChangedEvent.getSelection());
}
};
}
// Stop listening to the old one.
//
if (currentViewer != null)
{
currentViewer.removeSelectionChangedListener(selectionChangedListener);
}
// Start listening to the new one.
//
if (viewer != null)
{
viewer.addSelectionChangedListener(selectionChangedListener);
}
// Remember it.
//
currentViewer = viewer;
// Set the editors selection based on the current viewer's selection.
//
setSelection(currentViewer == null ? StructuredSelection.EMPTY : currentViewer.getSelection());
}
}
/**
* This returns the viewer as required by the {@link IViewerProvider} interface.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Viewer getViewer()
{
return currentViewer;
}
/**
* This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -