use of org.eclipse.ui.IPartListener2 in project org.csstudio.display.builder by kasemir.
the class DataBrowserEditor method createPartControl.
/**
* Create Plot GUI, connect to model via Controller
* {@inheritDoc}
*/
@Override
public void createPartControl(final Composite parent) {
// Create GUI elements (Plot)
parent.setLayout(new FillLayout());
final JFX_SWT_Wrapper wrapper = new JFX_SWT_Wrapper(parent, () -> {
try {
plot = new ModelBasedPlot(true);
} catch (Exception ex) {
logger.log(Level.WARNING, "Cannot create plot", ex);
}
return new Scene(plot.getPlot());
});
final Control plot_canvas = wrapper.getFXCanvas();
final Scene scene = wrapper.getScene();
JFXCursorFix.apply(scene, parent.getDisplay());
try {
hookDragAndDrop(plot_canvas);
} catch (Throwable ex) {
// Adding D&D to FXCanvas involves some hacking
// that might break as SWT internals get updated.
logger.log(Level.WARNING, "Cannot initialize Drag&Drop", ex);
}
// Create and start controller
controller = new ControllerSWT(parent.getShell(), model, plot);
try {
controller.start();
} catch (Exception ex) {
ExceptionDetailsErrorDialog.openError(parent.getShell(), Messages.Error, ex);
}
// Only the 'page' seems to know if a part is visible or not,
// so use PartListener to update controller's redraw handling
getSite().getPage().addPartListener(new IPartListener2() {
private boolean isThisEditor(final IWorkbenchPartReference part) {
return part.getPart(false) == DataBrowserEditor.this;
}
// Enable redraws...
@Override
public void partOpened(final IWorkbenchPartReference part) {
if (isThisEditor(part))
controller.suppressRedraws(false);
}
@Override
public void partVisible(final IWorkbenchPartReference part) {
if (isThisEditor(part))
controller.suppressRedraws(false);
}
// Suppress redraws...
@Override
public void partHidden(final IWorkbenchPartReference part) {
if (isThisEditor(part))
controller.suppressRedraws(true);
}
@Override
public void partClosed(final IWorkbenchPartReference part) {
if (isThisEditor(part))
controller.suppressRedraws(true);
}
// Ignore
@Override
public void partInputChanged(final IWorkbenchPartReference part) {
/* NOP */
}
@Override
public void partDeactivated(final IWorkbenchPartReference part) {
/* NOP */
}
@Override
public void partBroughtToTop(final IWorkbenchPartReference part) {
/* NOP */
}
@Override
public void partActivated(final IWorkbenchPartReference part) {
/* NOP */
}
});
toggle_legend = new ToggleLegendAction(plot.getPlot(), true);
toggle_toolbar = new ToggleToolbarAction(plot.getPlot(), true);
snapshot = new SnapshotAction(plot.getPlot(), parent.getShell());
createContextMenu(plot_canvas);
}
use of org.eclipse.ui.IPartListener2 in project mdw-designer by CenturyLinkCloud.
the class ProcessEditor method addActiveScriptEditor.
public void addActiveScriptEditor(final IEditorPart editor) {
if (!activeScriptEditors.contains(editor)) {
activeScriptEditors.add(editor);
editor.getSite().getPage().addPartListener(new IPartListener2() {
public void partClosed(IWorkbenchPartReference partRef) {
removeActiveScriptEditor(editor);
}
public void partActivated(IWorkbenchPartReference partRef) {
}
public void partBroughtToTop(IWorkbenchPartReference partRef) {
}
public void partDeactivated(IWorkbenchPartReference partRef) {
}
public void partOpened(IWorkbenchPartReference partRef) {
}
public void partHidden(IWorkbenchPartReference partRef) {
}
public void partVisible(IWorkbenchPartReference partRef) {
}
public void partInputChanged(IWorkbenchPartReference partRef) {
}
});
}
}
use of org.eclipse.ui.IPartListener2 in project org.csstudio.display.builder by kasemir.
the class DataBrowserAwareView method createPartControl.
/**
* Derived classes use doCreatePartControl,
* called by this method, which then hooks into the
* part listener which then tracks the current plot editor.
*/
@Override
public final void createPartControl(final Composite parent) {
doCreatePartControl(parent);
// Listen to the current 'part', react if it's a PlotEditor
part_listener = new IPartListener2() {
// Remember the editor when activated...
@Override
public void partActivated(IWorkbenchPartReference ref) {
if (ref.getId().equals(DataBrowserEditor.ID)) {
final IWorkbenchPart part = ref.getPart(false);
if (part instanceof DataBrowserEditor)
updateEditor((DataBrowserEditor) part);
// else: Some other editor of no concern
}
}
// ... until another one gets activated, or the current one closes.
@Override
public void partClosed(IWorkbenchPartReference ref) {
if (ref.getPart(false) == editor) {
updateEditor(null);
}
}
// All ignored
@Override
public void partDeactivated(IWorkbenchPartReference ref) {
/* NOP */
}
@Override
public void partBroughtToTop(IWorkbenchPartReference ref) {
/* NOP */
}
@Override
public void partHidden(IWorkbenchPartReference ref) {
/* NOP */
}
@Override
public void partInputChanged(IWorkbenchPartReference ref) {
/* NOP */
}
@Override
public void partOpened(IWorkbenchPartReference ref) {
/* NOP */
}
@Override
public void partVisible(IWorkbenchPartReference ref) {
/* NOP */
}
};
getSite().getPage().addPartListener(part_listener);
// If the active editor is already a plot editor,
// we will never get the 'activate' signal because
// it already happened.
// So check once, then use the PartListener
final IEditorPart current = getSite().getPage().getActiveEditor();
if (current instanceof DataBrowserEditor)
updateEditor((DataBrowserEditor) current);
else
updateEditor(null);
// When view is destroyed, we fake a null editor update.
// Since derived views already handle <code>updateModel</code>
// with a new <code>null</code> model, this will cause
// them to unsubscribe etc.
// Of course they can still add their own dispose listener.
//
// Note:
// Eclipse performs its own view lifecycle optimization.
// A view that's "closed" might actually just get hidden,
// and thus this dispose listener only takes effect when
// the application closes and really disposes the view.
//
// Unclear why the "Waveform" view gets disposed on close,
// while the "Config" view is kept around.
parent.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
getSite().getPage().removePartListener(part_listener);
updateEditor(null);
}
});
}
use of org.eclipse.ui.IPartListener2 in project mdw-designer by CenturyLinkCloud.
the class TaskTemplateEditor method init.
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
setSite(site);
textEditor = new StructuredTextEditor() {
@Override
public boolean isEditable() {
return false;
}
@Override
public boolean isEditorInputModifiable() {
return false;
}
@Override
public boolean isEditorInputReadOnly() {
return true;
}
@Override
public boolean isDirty() {
return false;
}
};
textEditor.setEditorPart(this);
if (input instanceof FileEditorInput) {
setInput(input);
IFile file = ((FileEditorInput) input).getFile();
WorkflowProject project = WorkflowProjectManager.getInstance().getWorkflowProject(file.getProject());
// force initialization
project.getDesignerProxy();
WorkflowPackage pkg = project.getPackage((IFolder) file.getParent());
taskTemplate = (TaskTemplate) pkg.getTaskTemplate(file);
// refresh from file system to make sure we're in sync
try {
Long taskId = taskTemplate.getId();
int version = taskTemplate.getVersion();
file.refreshLocal(IResource.DEPTH_ZERO, null);
String content = new String(PluginUtil.readFile(file));
TaskVO taskVO;
if (content.trim().startsWith("{")) {
taskVO = new TaskVO(new JSONObject(content));
} else {
TaskTemplateDocument doc = TaskTemplateDocument.Factory.parse(content);
com.centurylink.mdw.task.TaskTemplate fileTemplate = doc.getTaskTemplate();
taskVO = new TaskVO(fileTemplate);
}
taskTemplate.setTaskVO(taskVO);
taskVO.setName(file.getName());
taskVO.setTaskId(taskId);
taskTemplate.setId(taskId);
taskTemplate.setVersion(version);
taskVO.setPackageName(pkg.getName());
} catch (Exception ex) {
throw new PartInitException(ex.getMessage(), ex);
}
} else {
throw new PartInitException("Invalid input: " + input);
}
selectionProvider = new WorkflowSelectionProvider(taskTemplate);
site.setSelectionProvider(selectionProvider);
setPartName(taskTemplate.getName());
addPageChangedListener(new IPageChangedListener() {
public void pageChanged(PageChangedEvent event) {
if (getSelectedPage() == pages.get("Variables")) {
reconcileVariables();
}
}
});
partListener = new IPartListener2() {
public void partOpened(IWorkbenchPartReference partRef) {
// do nothing
}
public void partActivated(IWorkbenchPartReference partRef) {
IWorkbenchPart part = partRef.getPart(false);
if (part == TaskTemplateEditor.this && getSelectedPage() == pages.get("Variables"))
reconcileVariables();
}
public void partBroughtToTop(IWorkbenchPartReference partRef) {
// do nothing
}
public void partDeactivated(IWorkbenchPartReference partRef) {
// do nothing
}
public void partClosed(IWorkbenchPartReference partRef) {
// do nothing
}
public void partVisible(IWorkbenchPartReference partRef) {
// do nothing
}
public void partHidden(IWorkbenchPartReference partRef) {
// do nothing
}
public void partInputChanged(IWorkbenchPartReference partRef) {
// do nothing
}
};
getSite().getPage().addPartListener(partListener);
workbenchListener = new IWorkbenchListener() {
public boolean preShutdown(IWorkbench workbench, boolean forced) {
return MdwPlugin.getActivePage().closeEditor(TaskTemplateEditor.this, true);
}
public void postShutdown(IWorkbench workbench) {
// do nothing
}
};
PlatformUI.getWorkbench().addWorkbenchListener(workbenchListener);
}
Aggregations