Commit 241ea3a7 authored by Romain Bioteau's avatar Romain Bioteau

fix(design) add delete shortcut in property section list and tables

parent f8b61a8a
......@@ -51,7 +51,7 @@ public class DeleteHandler extends AbstractHandler {
Repository currentRepository = RepositoryManager.getInstance().getCurrentRepository();
if ((selectedResources.size() == 1 && FileActionDialog
.confirmDeletionQuestion(selectedResources.get(0).getName()))
|| FileActionDialog.confirmDeletionQuestionWithCustomMessage(
|| selectedResources.size() > 1 && FileActionDialog.confirmDeletionQuestionWithCustomMessage(
NLS.bind(IDEWorkbenchMessages.DeleteResourceAction_confirmN,
selectedResources.size()))) {
for (IResource res : selectedResources) {
......
......@@ -61,6 +61,8 @@ import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
......@@ -123,7 +125,16 @@ public abstract class ConnectorSection extends AbstractBonitaDescriptionSection
tableViewer.addDoubleClickListener(this);
tableViewer.addSelectionChangedListener(this);
tableViewer.getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL) {
e.doit = false;
removeSelectedConnectors();
}
}
});
tableViewer.setContentProvider(new EMFListFeatureTreeContentProvider(
getConnectorFeature()));
tableViewer.setLabelProvider(new StyledConnectorLabelProvider());
......@@ -174,50 +185,46 @@ public abstract class ConnectorSection extends AbstractBonitaDescriptionSection
}
}
/**
* @param buttonsComposite
* @return
*/
private Button createRemoveConnectorButton(final Composite buttonComposite) {
final Button removeButton = getWidgetFactory().createButton(
buttonComposite, Messages.removeData, SWT.FLAT);
removeButton.setLayoutData(GridDataFactory.fillDefaults()
.minSize(IDialogConstants.BUTTON_WIDTH, SWT.DEFAULT).create());
removeButton.addListener(SWT.Selection, new Listener() {
removeButton.addListener(SWT.Selection, e -> removeSelectedConnectors());
return removeButton;
}
@Override
public void handleEvent(final Event event) {
if (tableViewer != null
&& ((IStructuredSelection) tableViewer.getSelection())
.size() > 0) {
final List<?> selection = ((IStructuredSelection) tableViewer
.getSelection()).toList();
if (MessageDialog.openConfirm(buttonComposite.getShell(),
Messages.deleteDialogTitle, createMessage())) {
getEditingDomain().getCommandStack().execute(
new RemoveCommand(getEditingDomain(),
getEObject(), getConnectorFeature(),
selection));
tableViewer.refresh();
}
}
protected void removeSelectedConnectors() {
if (tableViewer != null
&& ((IStructuredSelection) tableViewer.getSelection())
.size() > 0) {
final List<?> selection = ((IStructuredSelection) tableViewer
.getSelection()).toList();
if (MessageDialog.openConfirm(Display.getDefault().getActiveShell(),
Messages.deleteDialogTitle, createMessage())) {
getEditingDomain().getCommandStack().execute(
new RemoveCommand(getEditingDomain(),
getEObject(), getConnectorFeature(),
selection));
tableViewer.refresh();
}
}
}
public String createMessage() {
final Object[] selection = ((IStructuredSelection) tableViewer
.getSelection()).toArray();
final StringBuilder res = new StringBuilder(
Messages.deleteDialogConfirmMessage);
res.append(' ');
res.append(((Connector) selection[0]).getName());
for (int i = 1; i < selection.length; i++) {
res.append(", ");res.append(((Connector) selection[i]).getName()); //$NON-NLS-1$
}
res.append(" ?"); //$NON-NLS-1$
return res.toString();
}
});
return removeButton;
public String createMessage() {
final Object[] selection = ((IStructuredSelection) tableViewer
.getSelection()).toArray();
final StringBuilder res = new StringBuilder(
Messages.deleteDialogConfirmMessage);
res.append(' ');
res.append(((Connector) selection[0]).getName());
for (int i = 1; i < selection.length; i++) {
res.append(", "); //$NON-NLS-1$
res.append(((Connector) selection[i]).getName());
}
res.append(" ?"); //$NON-NLS-1$
return res.toString();
}
protected Button createMoveConnectorButton(final Composite buttonsComposite) {
......
......@@ -71,6 +71,8 @@ import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
......@@ -169,6 +171,16 @@ public abstract class AbstractDataSection extends AbstractBonitaDescriptionSecti
dataTableViewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(200, 100).create());
dataTableViewer.setSorter(new ViewerSorter());
dataTableViewer.addDoubleClickListener(this);
dataTableViewer.getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL) {
e.doit = false;
removeData((IStructuredSelection) dataTableViewer.getSelection());
}
}
});
final ObservableListContentProvider contentProvider = new ObservableListContentProvider();
dataTableViewer.setContentProvider(contentProvider);
dataTableViewer.addFilter(hideBusinessObjectData());
......
......@@ -50,6 +50,8 @@ import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
......@@ -93,6 +95,16 @@ public abstract class DataViewer extends Composite {
editData();
}
});
tableViewer.getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL) {
e.doit = false;
removeData(dataContainerObservable, dataFeature);
}
}
});
addFilters(tableViewer);
final ObservableListContentProvider contentProvider = new ObservableListContentProvider();
tableViewer.setContentProvider(contentProvider);
......
......@@ -55,6 +55,8 @@ import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
......@@ -130,6 +132,17 @@ public class DocumentPropertySection extends AbstractBonitaDescriptionSection
documentListViewer.setContentProvider(new ObservableListContentProvider());
documentListViewer.addDoubleClickListener(this);
documentListViewer.addSelectionChangedListener(this);
documentListViewer.getList().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL) {
e.doit = false;
removeDocuments();
}
}
});
return documentListViewer;
}
......@@ -184,40 +197,44 @@ public class DocumentPropertySection extends AbstractBonitaDescriptionSection
@Override
public void widgetSelected(final SelectionEvent e) {
super.widgetSelected(e);
final int ok = 0;
if (ok == openOutlineDialog((IStructuredSelection) documentListViewer.getSelection())) {
final Iterator<Document> selection = ((IStructuredSelection) documentListViewer.getSelection())
.iterator();
if (selection.hasNext()) {
final RefactorDocumentOperation rdo = createDeleteRefactorOperation(selection);
executeDeleteReactorOperation(rdo);
documentListViewer.refresh();
documentListViewer.setSelection(new StructuredSelection());
}
}
removeDocuments();
}
private void executeDeleteReactorOperation(final RefactorDocumentOperation rdo) {
try {
rdo.run(new NullProgressMonitor());
} catch (final InvocationTargetException e1) {
BonitaStudioLog.error(e1);
} catch (final InterruptedException e1) {
BonitaStudioLog.error(e1);
}
}
});
}
private RefactorDocumentOperation createDeleteRefactorOperation(final Iterator<Document> selection) {
final RefactorDocumentOperation rdo = new RefactorDocumentOperation(RefactoringOperationType.REMOVE);
rdo.setEditingDomain(getEditingDomain());
rdo.setAskConfirmation(true);
while (selection.hasNext()) {
rdo.addItemToRefactor(null, selection.next());
}
return rdo;
protected void removeDocuments() {
final int ok = 0;
if (ok == openOutlineDialog((IStructuredSelection) documentListViewer.getSelection())) {
final Iterator<Document> selection = ((IStructuredSelection) documentListViewer.getSelection())
.iterator();
if (selection.hasNext()) {
final RefactorDocumentOperation rdo = createDeleteRefactorOperation(selection);
executeDeleteReactorOperation(rdo);
documentListViewer.refresh();
documentListViewer.setSelection(new StructuredSelection());
}
});
}
}
private void executeDeleteReactorOperation(final RefactorDocumentOperation rdo) {
try {
rdo.run(new NullProgressMonitor());
} catch (final InvocationTargetException e1) {
BonitaStudioLog.error(e1);
} catch (final InterruptedException e1) {
BonitaStudioLog.error(e1);
}
}
private RefactorDocumentOperation createDeleteRefactorOperation(final Iterator<Document> selection) {
final RefactorDocumentOperation rdo = new RefactorDocumentOperation(RefactoringOperationType.REMOVE);
rdo.setEditingDomain(getEditingDomain());
rdo.setAskConfirmation(true);
while (selection.hasNext()) {
rdo.addItemToRefactor(null, selection.next());
}
return rdo;
}
@Override
......
......@@ -74,6 +74,8 @@ import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
......@@ -156,6 +158,16 @@ public class ParameterPropertySection extends AbstractBonitaDescriptionSection i
parameterTableViewer.setSorter(new ViewerSorter());
parameterTableViewer.addDoubleClickListener(this);
parameterTableViewer.addSelectionChangedListener(this);
parameterTableViewer.getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.DEL) {
e.doit = false;
remove();
}
}
});
parameterTableViewer.setContentProvider(new ArrayContentProvider());
parameterTableViewer.setLabelProvider(new ParameterStyledLabelProvider());
......@@ -169,49 +181,58 @@ public class ParameterPropertySection extends AbstractBonitaDescriptionSection i
@Override
public void widgetSelected(final SelectionEvent e) {
final IStructuredSelection selection = (IStructuredSelection) parameterTableViewer.getSelection();
final StringBuilder sb = new StringBuilder();
for (final Object selectionElement : selection.toList()) {
if (selectionElement instanceof Parameter) {
sb.append(((Parameter) selectionElement).getName() + "\n");
}
}
if (sb.length() > 0) {
sb.delete(sb.length() - 1, sb.length());
}
final String[] buttonList = { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL };
final List<Object> selectionList = ((IStructuredSelection) parameterTableViewer.getSelection()).toList();
final OutlineDialog dialog = new OutlineDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), removalConfirmationDialogTitle, Display
.getCurrent().getSystemImage(SWT.ICON_WARNING), NLS.bind(Messages.areYouSureMessage, sb.toString()), MessageDialog.CONFIRM, buttonList,
1, selectionList);
final int ok = 0;
if (ok == dialog.open()) {
for (final Object parameter : selection.toList()) {
final RemoveParametersOperation op = new RemoveParametersOperation((Parameter) parameter, (AbstractProcess) getEObject());
op.setEditingDomain(getEditingDomain());
op.setAskConfirmation(true);
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
try {
service.busyCursorWhile(op);
} catch (final InvocationTargetException ex) {
BonitaStudioLog.error(ex);
} catch (final InterruptedException ex) {
BonitaStudioLog.error(ex);
}
}
parameterTableViewer.refresh();
try {
RepositoryManager.getInstance().getCurrentRepository().getProject()
.build(IncrementalProjectBuilder.FULL_BUILD, XtextProjectHelper.BUILDER_ID, Collections.<String, String> emptyMap(), null);
} catch (final CoreException e1) {
BonitaStudioLog.error(e1, ParameterPlugin.PLUGIN_ID);
}
}
remove();
}
});
}
protected void remove() {
final IStructuredSelection selection = (IStructuredSelection) parameterTableViewer.getSelection();
final StringBuilder sb = new StringBuilder();
for (final Object selectionElement : selection.toList()) {
if (selectionElement instanceof Parameter) {
sb.append(((Parameter) selectionElement).getName() + "\n");
}
}
if (sb.length() > 0) {
sb.delete(sb.length() - 1, sb.length());
}
final String[] buttonList = { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL };
final List<Object> selectionList = ((IStructuredSelection) parameterTableViewer.getSelection()).toList();
final OutlineDialog dialog = new OutlineDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
removalConfirmationDialogTitle, Display
.getCurrent().getSystemImage(SWT.ICON_WARNING),
NLS.bind(Messages.areYouSureMessage, sb.toString()), MessageDialog.CONFIRM, buttonList,
1, selectionList);
final int ok = 0;
if (ok == dialog.open()) {
for (final Object parameter : selection.toList()) {
final RemoveParametersOperation op = new RemoveParametersOperation((Parameter) parameter,
(AbstractProcess) getEObject());
op.setEditingDomain(getEditingDomain());
op.setAskConfirmation(true);
final IProgressService service = PlatformUI.getWorkbench().getProgressService();
try {
service.busyCursorWhile(op);
} catch (final InvocationTargetException ex) {
BonitaStudioLog.error(ex);
} catch (final InterruptedException ex) {
BonitaStudioLog.error(ex);
}
}
parameterTableViewer.refresh();
try {
RepositoryManager.getInstance().getCurrentRepository().getProject()
.build(IncrementalProjectBuilder.FULL_BUILD, XtextProjectHelper.BUILDER_ID,
Collections.<String, String> emptyMap(), null);
} catch (final CoreException e1) {
BonitaStudioLog.error(e1, ParameterPlugin.PLUGIN_ID);
}
}
}
protected Parameter createDefaultParameter() {
final Parameter param = ParameterFactory.eINSTANCE.createParameter();
final AbstractProcess process = (AbstractProcess) getEObject();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment