use of org.eclipse.ui.IPartListener in project liferay-ide by liferay.
the class AbstractKaleoEditorHelper method openEditor.
public void openEditor(ISapphirePart sapphirePart, Element modelElement, ValueProperty valueProperty) {
try {
Object content = modelElement.property(valueProperty).content();
if (content == null) {
content = "";
}
IProject project = sapphirePart.adapt(IProject.class);
IEditorInput editorInput = modelElement.adapt(IEditorInput.class);
String name = editorInput.getName();
Node node = modelElement.nearest(Node.class);
String nodeName = node.getName().content();
HiddenFileEditorInput hiddenFileEditorInput = _getHiddenFileEditorInput(project, name, nodeName, content.toString());
IEditorSite editorSite = sapphirePart.adapt(IEditorSite.class);
IWorkbenchWindow wbWindow = editorSite.getWorkbenchWindow();
IEditorPart editorPart = wbWindow.getActivePage().openEditor(hiddenFileEditorInput, _editorId);
ITextEditor textEditor = (ITextEditor) editorPart.getAdapter(ITextEditor.class);
IDocumentListener documentListener = new IDocumentListener() {
public void documentAboutToBeChanged(DocumentEvent event) {
}
public void documentChanged(DocumentEvent event) {
String contents = event.getDocument().get();
modelElement.property(valueProperty).write(contents);
}
};
IDocumentProvider documentProvider = textEditor.getDocumentProvider();
documentProvider.getDocument(hiddenFileEditorInput).addDocumentListener(documentListener);
IWorkbenchPartSite wbPartSite = editorPart.getSite();
IPartListener partListener = new IPartListener() {
public void partActivated(IWorkbenchPart part) {
}
public void partBroughtToTop(IWorkbenchPart part) {
}
public void partClosed(IWorkbenchPart part) {
if ((part != null) && part.equals(editorPart)) {
new WorkspaceJob("delete temp editor file") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
IFile file = hiddenFileEditorInput.getFile();
file.getParent().delete(true, null);
} catch (CoreException ce) {
}
return Status.OK_STATUS;
}
}.schedule(100);
}
}
public void partDeactivated(IWorkbenchPart part) {
}
public void partOpened(IWorkbenchPart part) {
}
};
wbPartSite.getPage().addPartListener(partListener);
} catch (Exception e) {
KaleoUI.logError("Error opening editor.", e);
}
}
use of org.eclipse.ui.IPartListener in project polymap4-core by Polymap4.
the class LinkEditorAction method init.
/**
* @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
*/
protected void init() {
partListener = new IPartListener() {
public void partActivated(IWorkbenchPart part) {
if (part instanceof IEditorPart && !ignoreEditorActivation) {
updateSelectionJob.schedule(NavigatorPlugin.LINK_HELPER_DELAY);
}
}
public void partBroughtToTop(IWorkbenchPart part) {
if (part instanceof IEditorPart && !ignoreEditorActivation) {
updateSelectionJob.schedule(NavigatorPlugin.LINK_HELPER_DELAY);
}
}
public void partClosed(IWorkbenchPart part) {
}
public void partDeactivated(IWorkbenchPart part) {
}
public void partOpened(IWorkbenchPart part) {
}
};
updateLinkingEnabled(commonNavigator.isLinkingEnabled());
commonNavigator.addPropertyListener(this);
// linkHelperRegistry = new
// LinkHelperManager(commonViewer.getNavigatorContentService());
}
use of org.eclipse.ui.IPartListener in project statecharts by Yakindu.
the class StatechartDiagramGlobalActionHandlerProvider method getGlobalActionHandler.
/*
* (non-Javadoc)
*
* @see org.eclipse.gmf.runtime.common.ui.services.action.global.IGlobalActionHandlerProvider#getGlobalActionHandler(org.eclipse.gmf.runtime.common.ui.services.action.global.IGlobalActionHandlerContext)
*/
@SuppressWarnings("unchecked")
public IGlobalActionHandler getGlobalActionHandler(final IGlobalActionHandlerContext context) {
/* create the handler */
if (!getHandlerList().containsKey(context.getActivePart())) {
// PATCH START
getHandlerList().put(context.getActivePart(), new StatechartDiagramGlobalActionHandler());
// PATCH END
/*
* register as a part listener so that the cache can be cleared when
* the part is disposed
*/
context.getActivePart().getSite().getPage().addPartListener(new IPartListener() {
private IWorkbenchPart localPart = context.getActivePart();
/**
* @see org.eclipse.ui.IPartListener#partActivated(IWorkbenchPart)
*/
public void partActivated(IWorkbenchPart part) {
// NULL implementation
}
/**
* @see org.eclipse.ui.IPartListener#partBroughtToTop(IWorkbenchPart)
*/
public void partBroughtToTop(IWorkbenchPart part) {
// NULL implementation
}
/**
* @see org.eclipse.ui.IPartListener#partClosed(IWorkbenchPart)
*/
public void partClosed(IWorkbenchPart part) {
/* remove the cache associated with the part */
if (part != null && part == localPart && getHandlerList().containsKey(part)) {
getHandlerList().remove(part);
localPart.getSite().getPage().removePartListener(this);
localPart = null;
}
}
/**
* @see org.eclipse.ui.IPartListener#partDeactivated(IWorkbenchPart)
*/
public void partDeactivated(IWorkbenchPart part) {
// NULL implementation
}
/**
* @see org.eclipse.ui.IPartListener#partOpened(IWorkbenchPart)
*/
public void partOpened(IWorkbenchPart part) {
// NULL implementation
}
});
}
return (DiagramGlobalActionHandler) getHandlerList().get(context.getActivePart());
}
Aggregations