From e0fca17cf7f8b142a1f99754a5e11769d6e82aab Mon Sep 17 00:00:00 2001 From: Philip Wenig Date: Thu, 16 Sep 2021 10:00:30 +0200 Subject: [PATCH] Fixed #740 - Process Method Editor - add delete all option --- .../methods/ListProcessEntryContainer.java | 5 ++++ .../xxd/ui/swt/ProcessMethodToolbar.java | 27 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/methods/ListProcessEntryContainer.java b/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/methods/ListProcessEntryContainer.java index db06539a62..bc48fde641 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/methods/ListProcessEntryContainer.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.model/src/org/eclipse/chemclipse/model/methods/ListProcessEntryContainer.java @@ -161,6 +161,11 @@ public void removeProcessEntry(IProcessEntry processEntry) { getEntries().remove(processEntry); } + public void removeAllProcessEntries() { + + getEntries().clear(); + } + public boolean isReadOnly() { return readOnly; diff --git a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/ProcessMethodToolbar.java b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/ProcessMethodToolbar.java index 3d05270b6a..0750517e77 100644 --- a/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/ProcessMethodToolbar.java +++ b/chemclipse/plugins/org.eclipse.chemclipse.ux.extension.xxd.ui/src/org/eclipse/chemclipse/ux/extension/xxd/ui/swt/ProcessMethodToolbar.java @@ -70,6 +70,7 @@ public class ProcessMethodToolbar extends ToolBar { private ToolItem buttonAdd; private ToolItem buttonCopy; private ToolItem buttonRemove; + private ToolItem buttonRemoveAll; private ToolItem buttonMoveUp; private ToolItem buttonMoveDown; private ToolItem buttonClipboard; @@ -138,7 +139,9 @@ public void updateTableButtons() { buttonAdd.setEnabled(isEditable); // IStructuredSelection selection = structuredViewer.getStructuredSelection(); - boolean writeable = processMethod != null && !processMethod.isFinal() && !selection.isEmpty(); + boolean canEdit = processMethod != null && !processMethod.isFinal(); + boolean writeable = canEdit && !selection.isEmpty(); + // Iterator iterator = selection.iterator(); while(iterator.hasNext() && writeable) { Object object = iterator.next(); @@ -151,6 +154,7 @@ public void updateTableButtons() { boolean readOnly = processMethod != null && (processMethod.isReadOnly() || this.readOnly); buttonCopy.setEnabled(writeable && !readOnly); buttonRemove.setEnabled(writeable && !readOnly); + buttonRemoveAll.setEnabled(canEdit && processMethod.getNumberOfEntries() > 0 && !readOnly); buttonMoveUp.setEnabled(writeable && !readOnly); buttonMoveDown.setEnabled(writeable && !readOnly); buttonClipboard.setEnabled(true); @@ -234,6 +238,7 @@ private void createControl() { buttonAdd = createAddButton(this); buttonRemove = createRemoveButton(this); + buttonRemoveAll = createRemoveAllButton(this); buttonCopy = createCopyButton(this); buttonMoveUp = createMoveUpButton(this); buttonMoveDown = createMoveDownButton(this); @@ -371,6 +376,26 @@ public void widgetSelected(SelectionEvent e) { return item; } + private ToolItem createRemoveAllButton(ToolBar toolBar) { + + final ToolItem item = new ToolItem(toolBar, SWT.PUSH); + item.setImage(ApplicationImageFactory.getInstance().getImage(IApplicationImage.IMAGE_DELETE_ALL, IApplicationImage.SIZE_16x16)); + item.setToolTipText("Remove all process method(s)."); + item.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + + if(MessageDialog.openQuestion(toolBar.getShell(), "Delete Process Method(s)", "Would you like to delete all processor(s)?")) { + processMethod.removeAllProcessEntries(); + fireUpdate(); + select(Collections.emptyList()); + } + } + }); + return item; + } + private ToolItem createCopyButton(ToolBar toolBar) { final ToolItem item = new ToolItem(toolBar, SWT.PUSH);