use of org.eclipse.ui.IWorkbench in project linuxtools by eclipse.
the class SystemTapScriptGraphOptionsTab method createColumnSelector.
private void createColumnSelector(Composite parent) {
GridLayout layout = new GridLayout();
parent.setLayout(layout);
Composite topLayout = new Composite(parent, SWT.NONE);
topLayout.setLayout(new GridLayout(1, false));
topLayout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
Button generateExpsButton = new Button(topLayout, SWT.PUSH);
generateExpsButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
generateExpsButton.setText(Messages.SystemTapScriptGraphOptionsTab_generateFromPrintsButton);
generateExpsButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_generateFromPrintsTooltip);
generateExpsButton.addSelectionListener(regexGenerator);
Composite regexButtonLayout = new Composite(parent, SWT.NONE);
regexButtonLayout.setLayout(new GridLayout(3, false));
regexButtonLayout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Label selectedRegexLabel = new Label(regexButtonLayout, SWT.NONE);
selectedRegexLabel.setText(Messages.SystemTapScriptGraphOptionsTab_regexLabel);
selectedRegexLabel.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_regexTooltip);
regularExpressionCombo = new Combo(regexButtonLayout, SWT.DROP_DOWN);
regularExpressionCombo.setTextLimit(MAX_REGEX_LENGTH);
regularExpressionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
regularExpressionCombo.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
int selected = regularExpressionCombo.getSelectionIndex();
if (selected == selectedRegex) {
return;
}
// If deselecting an empty regular expression, delete it automatically.
if (regularExpressionCombo.getItem(selectedRegex).isEmpty() && graphsDataList.get(selectedRegex).size() == 0 && outputList.get(selectedRegex).isEmpty()) {
// Otherwise, the deleted blank entry would be replaced by another blank entry.
if (selected == regularExpressionCombo.getItemCount() - 1) {
// To keep the text blank.
regularExpressionCombo.select(selectedRegex);
return;
}
removeRegex(false);
if (selected > selectedRegex) {
selected--;
}
}
// update all appropriate values to make room for a new regular expression.
if (selected == regularExpressionCombo.getItemCount() - 1 && getNumberOfRegexs() < MAX_NUMBER_OF_REGEXS) {
// $NON-NLS-1$
outputList.add("");
regexErrorMessages.add(null);
columnNamesList.add(new ArrayList<String>());
cachedNamesList.add(new Stack<String>());
graphsDataList.add(new LinkedList<GraphData>());
// Remove "Add New Regex" from the selected combo item; make it blank.
// $NON-NLS-1$
regularExpressionCombo.setItem(selected, "");
regularExpressionCombo.select(selected);
updateRegexSelection(selected, false);
updateLaunchConfigurationDialog();
// (Don't do this _every_ time something is added.)
if (getNumberOfRegexs() == 2) {
removeRegexButton.setEnabled(true);
}
if (getNumberOfRegexs() < MAX_NUMBER_OF_REGEXS) {
regularExpressionCombo.add(Messages.SystemTapScriptGraphOptionsTab_regexAddNew);
}
} else {
updateRegexSelection(selected, false);
}
}));
regularExpressionCombo.addModifyListener(regexListener);
removeRegexButton = new Button(regexButtonLayout, SWT.PUSH);
removeRegexButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
removeRegexButton.setText(Messages.SystemTapScriptGraphOptionsTab_regexRemove);
removeRegexButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
IWorkbench workbench = PlatformUI.getWorkbench();
MessageDialog dialog = new MessageDialog(workbench.getActiveWorkbenchWindow().getShell(), Messages.SystemTapScriptGraphOptionsTab_removeRegexTitle, null, MessageFormat.format(Messages.SystemTapScriptGraphOptionsTab_removeRegexAsk, regularExpressionCombo.getItem(selectedRegex)), MessageDialog.QUESTION, new String[] { "Yes", "No" }, // $NON-NLS-1$ //$NON-NLS-2$
0);
int result = dialog.open();
if (result == 0) {
// Yes
removeRegex(true);
}
}));
GridLayout twoColumns = new GridLayout(2, false);
Composite regexSummaryComposite = new Composite(parent, SWT.NONE);
regexSummaryComposite.setLayout(twoColumns);
regexSummaryComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Label sampleOutputLabel = new Label(regexSummaryComposite, SWT.NONE);
sampleOutputLabel.setText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputLabel);
sampleOutputLabel.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputTooltip);
this.sampleOutputText = new Text(regexSummaryComposite, SWT.BORDER);
this.sampleOutputText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.sampleOutputText.addModifyListener(sampleOutputListener);
sampleOutputText.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputTooltip);
Composite expressionTableLabels = new Composite(parent, SWT.NONE);
expressionTableLabels.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
expressionTableLabels.setLayout(twoColumns);
Label label = new Label(expressionTableLabels, SWT.NONE);
label.setText(Messages.SystemTapScriptGraphOptionsTab_columnTitle);
label.setAlignment(SWT.LEFT);
Label label2 = new Label(expressionTableLabels, SWT.NONE);
label2.setAlignment(SWT.LEFT);
label2.setText(Messages.SystemTapScriptGraphOptionsTab_extractedValueLabel);
ScrolledComposite regexTextScrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.BORDER);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
data.heightHint = 200;
regexTextScrolledComposite.setLayoutData(data);
textFieldsComposite = new Composite(regexTextScrolledComposite, SWT.NONE);
textFieldsComposite.setLayout(new GridLayout(4, false));
regexTextScrolledComposite.setContent(textFieldsComposite);
regexTextScrolledComposite.setExpandHorizontal(true);
// To position the column labels properly, add a dummy column and use its children's sizes for reference.
// This is necessary since expressionTableLabels can't share a layout with textFieldsComposite.
textListenersEnabled = false;
addColumn(null);
data = new GridData(SWT.FILL, SWT.FILL, false, false);
data.horizontalIndent = textFieldsComposite.getChildren()[2].getLocation().x;
data.widthHint = textFieldsComposite.getChildren()[2].getSize().x;
label.setLayoutData(data);
label2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
removeColumn(false);
textListenersEnabled = true;
}
use of org.eclipse.ui.IWorkbench in project linuxtools by eclipse.
the class KernelSourceAction method run.
/**
* The main code body for this action. Causes one of the following to occur:
* <ul>
* <li>If the selected node is clickable, as specified in <code>TreeNode.isClickable</code>
* the browser creates an instance of <code>CEditor</code> on the file specified in the selection
* (<code>KernelBrowserView</code>'s tree only marks clickable on files, not folders) and
* opens it on the current window</li>
* <li>If the selected node is not clickable, the code runs the action specified in
* <code>TreeExpandCollapseAction</code></li>
* @see org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.c.CEditor
* @see TreeNode#isClickable()
* @see TreeExpandCollapseAction
*/
@Override
public void run() {
IWorkbench wb = PlatformUI.getWorkbench();
Object o = getSelectedElement();
if (o instanceof TreeNode) {
TreeNode t = (TreeNode) o;
if (t.isClickable()) {
IFileStore fs = (IFileStore) t.getData();
if (fs != null) {
IEditorInput input = new FileStoreEditorInput(fs);
try {
wb.getActiveWorkbenchWindow().getActivePage().openEditor(input, CDT_EDITOR_ID);
} catch (PartInitException e) {
// $NON-NLS-1$
ExceptionErrorDialog.openError(Localization.getString("KernelSourceAction.CantOpenEditor"), e);
}
}
} else {
runExpandAction();
}
}
}
use of org.eclipse.ui.IWorkbench in project linuxtools by eclipse.
the class UIUtils method getWorkbench.
/**
* Gets the workbench.
*
* @return the workbench
*/
public static IWorkbench getWorkbench() {
IWorkbench workbench = PlatformUI.getWorkbench();
Assert.isNotNull(workbench);
return workbench;
}
use of org.eclipse.ui.IWorkbench in project knime-core by knime.
the class WorkflowEditor method dispose.
/**
* Deregisters all listeners when the editor is disposed.
*
* @see org.eclipse.ui.IWorkbenchPart#dispose()
*/
@Override
public void dispose() {
NodeLogger.getLogger(WorkflowEditor.class).debug("Disposing editor...");
if (m_zoomWheelListener != null) {
m_zoomWheelListener.dispose();
}
if (m_fileResource != null && m_manager != null) {
// disposed is also called when workflow load fails or is canceled
ProjectWorkflowMap.unregisterClientFrom(m_fileResource, this);
// removes the workflow from memory
ProjectWorkflowMap.remove(m_fileResource);
if (isTempRemoteWorkflowEditor()) {
// after the workflow is deleted we can delete the temp location
final AbstractExplorerFileStore flowLoc = getFileStore(m_fileResource);
if (flowLoc != null) {
new Thread(() -> {
try {
m_workflowCanBeDeleted.acquire();
File d = flowLoc.toLocalFile();
if (d != null && d.exists()) {
FileUtils.deleteDirectory(d.getParentFile());
}
} catch (CoreException | IOException | InterruptedException e) {
LOGGER.warn("Error during deletion of temporary workflow location: " + e.getMessage(), e);
}
}, "Delete temporary copy of " + m_origRemoteLocation).start();
}
}
}
final ReferencedFile autoSaveDirectory;
if (m_manager != null && m_parentEditor == null && m_fileResource != null) {
autoSaveDirectory = Wrapper.unwrapWFMOptional(m_manager).map(wfm -> wfm.getAutoSaveDirectory()).orElse(null);
} else {
autoSaveDirectory = null;
}
// remember that this editor has been closed
m_closed = true;
for (IEditorPart child : getSubEditors()) {
child.getEditorSite().getPage().closeEditor(child, false);
}
NodeProvider.INSTANCE.removeListener(this);
getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(this);
if (m_parentEditor != null && m_manager != null) {
// Store the editor settings with the metanode
if (getWorkflowManagerUI().isDirty()) {
// doesn't persist settings to disk
saveEditorSettingsToWorkflowManager();
}
// bug fix 2051: Possible memory leak related to sub-flow editor.
// metanode editors were still referenced by the EditorHistory
IWorkbench workbench = PlatformUI.getWorkbench();
if (workbench instanceof Workbench) {
EditorHistory hist = ((Workbench) workbench).getEditorHistory();
WorkflowManagerInput wfmInput = new WorkflowManagerInput(m_manager, m_parentEditor);
hist.remove(wfmInput);
}
}
if (m_autoSaveJob != null) {
m_autoSaveJob.cancel();
m_autoSaveJob = null;
}
// unregisters wfm listeners
setWorkflowManager(null);
if (autoSaveDirectory != null) {
KNIMEConstants.GLOBAL_THREAD_POOL.enqueue(new Runnable() {
@Override
public void run() {
LOGGER.debugWithFormat("Deleting auto-saved copy (\"%s\")...", autoSaveDirectory);
try {
FileUtils.deleteDirectory(autoSaveDirectory.getFile());
} catch (IOException e) {
LOGGER.error(String.format("Failed to delete auto-saved copy of workflow (folder \"%s\"): %s", autoSaveDirectory, e.getMessage()), e);
}
}
});
}
getCommandStack().removeCommandStackListener(this);
IPreferenceStore prefStore = KNIMEUIPlugin.getDefault().getPreferenceStore();
prefStore.removePropertyChangeListener(this);
super.dispose();
}
use of org.eclipse.ui.IWorkbench in project knime-core by knime.
the class WorkflowEditor method saveTo.
/**
* Save workflow to resource.
*
* @param fileResource .. the resource, usually m_fileResource or m_autoSaveFileResource or soon-to-be
* m_fileResource (for save-as)
* @param monitor ...
* @param saveWithData ... save data also
* @param newContext a new workflow context for the saved workflow; if this is non-<code>null</code>, a "save as" is
* performed
*/
private void saveTo(final URI fileResource, final IProgressMonitor monitor, final boolean saveWithData, final WorkflowContext newContext) {
LOGGER.debug("Saving workflow " + getWorkflowManager().get().getNameWithID());
// Exception messages from the inner thread
final StringBuilder exceptionMessage = new StringBuilder();
if (fileResource == null && m_parentEditor != null) {
m_parentEditor.doSave(monitor);
m_isDirty = false;
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
firePropertyChange(IEditorPart.PROP_DIRTY);
}
});
return;
}
// attach editor properties with the workflow manager - for all sub editors too
saveEditorSettingsToWorkflowManager();
/* TODO: EditorSettings should be saved on all child editors too. But this triggers them dirty. And they stay
* dirty even after save (and setting them clean!). The dirty flag is a mess. Needs to be cleaned up!
* And after that, we may not inherit the zoom level (in metanodes) from the parent anymore
* (see #applyEditorSettingsFromWorkflowManager).
* for (IEditorPart subEditor : getSubEditors()) {
* ((WorkflowEditor)subEditor).saveEditorSettingsToWorkflowManager();
* }
*/
// to be sure to mark dirty and inform the user about running nodes
// we ask for the state BEFORE saving
// this flag is evaluated at the end of this method
boolean wasInProgress = false;
try {
final File workflowDir = new File(fileResource);
AbstractSaveRunnable saveRunnable;
if (newContext != null) {
saveRunnable = new SaveAsRunnable(this, exceptionMessage, monitor, newContext);
} else {
WorkflowSaveHelper saveHelper = new WorkflowSaveHelper(saveWithData, false);
saveRunnable = new InplaceSaveRunnable(this, exceptionMessage, saveHelper, monitor, workflowDir);
}
IWorkbench wb = PlatformUI.getWorkbench();
IProgressService ps = wb.getProgressService();
NodeContainerState state = m_manager.getNodeContainerState();
wasInProgress = state.isExecutionInProgress() && !state.isExecutingRemotely();
ps.run(true, false, saveRunnable);
// this code is usually (always?) run in the UI thread but in case it's not we schedule in UI thread
// (SVG export always in UI thread)
final File svgFile = new File(workflowDir, WorkflowPersistor.SVG_WORKFLOW_FILE);
svgFile.delete();
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
if (m_manager.isProject()) {
saveSVGImage(svgFile);
}
}
});
// mark command stack (no undo beyond this point)
getCommandStack().markSaveLocation();
} catch (Exception e) {
LOGGER.error("Could not save workflow: " + exceptionMessage, e);
// inform the user
if (exceptionMessage.length() > 0) {
showInfoMessage("Workflow could not be saved ...", exceptionMessage.toString());
}
throw new OperationCanceledException("Workflow was not saved: " + exceptionMessage.toString());
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!Display.getDefault().isDisposed() && (m_manager != null)) {
// mark all sub editors as saved
for (IEditorPart subEditor : getSubEditors()) {
final WorkflowEditor editor = (WorkflowEditor) subEditor;
((WorkflowEditor) subEditor).setIsDirty(false);
editor.firePropertyChange(IEditorPart.PROP_DIRTY);
}
}
}
});
monitor.done();
// or simply saves (Ctrl+S)
if (wasInProgress) {
markDirty();
final Pointer<Boolean> abortPointer = new Pointer<Boolean>();
abortPointer.set(Boolean.FALSE);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
boolean abort = false;
Shell sh = Display.getDefault().getActiveShell();
String title = "Workflow in execution";
String message = "Executing nodes are not saved!";
if (m_isClosing) {
abort = !MessageDialog.openQuestion(sh, title, message + " Exit anyway?");
// user canceled close
m_isClosing = !abort;
} else {
IPreferenceStore prefStore = KNIMEUIPlugin.getDefault().getPreferenceStore();
String toogleMessage = "Don't warn me again";
if (prefStore.getBoolean(PreferenceConstants.P_CONFIRM_EXEC_NODES_NOT_SAVED)) {
MessageDialogWithToggle.openInformation(sh, title, message, toogleMessage, false, prefStore, PreferenceConstants.P_CONFIRM_EXEC_NODES_NOT_SAVED);
}
}
abortPointer.set(Boolean.valueOf(abort));
}
});
if (abortPointer.get()) {
throw new OperationCanceledException("Closing workflow canceled on user request.");
}
}
}
Aggregations