X-Git-Url: http://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=core%2Forg.argeo.suite.ui%2Fsrc%2Forg%2Fargeo%2Fsuite%2Fui%2Fwidgets%2FAbstractConnectContextMenu.java;fp=core%2Forg.argeo.suite.ui%2Fsrc%2Forg%2Fargeo%2Fsuite%2Fui%2Fwidgets%2FAbstractConnectContextMenu.java;h=0000000000000000000000000000000000000000;hp=07f9cee9353e912f61f32deaf13835abda1da004;hb=3440f51df3e4c015972c7b6a0efb3ce16188b89b;hpb=752a7b2614895002a3d184be166ef4162caf0d05 diff --git a/core/org.argeo.suite.ui/src/org/argeo/suite/ui/widgets/AbstractConnectContextMenu.java b/core/org.argeo.suite.ui/src/org/argeo/suite/ui/widgets/AbstractConnectContextMenu.java deleted file mode 100644 index 07f9cee..0000000 --- a/core/org.argeo.suite.ui/src/org/argeo/suite/ui/widgets/AbstractConnectContextMenu.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.argeo.suite.ui.widgets; - -import java.util.HashMap; -import java.util.Map; - -import org.argeo.cms.ui.util.CmsUiUtils; -import org.argeo.eclipse.ui.EclipseUiUtils; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.ShellEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** - * Generic popup context menu for TableViewer to enable single sourcing between - * CMS and Workbench - */ -public abstract class AbstractConnectContextMenu { - - private Shell parentShell; - private Shell shell; - // Local context - - private final static String KEY_ACTION_ID = "actionId"; - private final String[] defaultActions; - private Map actionButtons = new HashMap(); - - public AbstractConnectContextMenu(Display display, String[] defaultActions) { - parentShell = display.getActiveShell(); - shell = new Shell(parentShell, SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP); - this.defaultActions = defaultActions; - } - - protected void createControl() { - shell.setLayout(EclipseUiUtils.noSpaceGridLayout()); - Composite boxCmp = new Composite(shell, SWT.NO_FOCUS | SWT.BORDER); - boxCmp.setLayout(EclipseUiUtils.noSpaceGridLayout()); -// CmsUiUtils.style(boxCmp, ConnectUiStyles.CONTEXT_MENU_BOX); - createContextMenu(boxCmp); - shell.addShellListener(new ActionsShellListener()); - } - - protected void createContextMenu(Composite boxCmp) { - ActionsSelListener asl = new ActionsSelListener(); - for (String actionId : defaultActions) { - Button btn = new Button(boxCmp, SWT.FLAT | SWT.LEAD); - btn.setText(getLabel(actionId)); - btn.setLayoutData(EclipseUiUtils.fillWidth()); - CmsUiUtils.markup(btn); -// CmsUiUtils.style(btn, actionId + ConnectUiStyles.BUTTON_SUFFIX); - btn.setData(KEY_ACTION_ID, actionId); - btn.addSelectionListener(asl); - actionButtons.put(actionId, btn); - } - } - - protected void setVisible(boolean visible, String... buttonIds) { - for (String id : buttonIds) { - Button button = actionButtons.get(id); - button.setVisible(visible); - GridData gd = (GridData) button.getLayoutData(); - gd.heightHint = visible ? SWT.DEFAULT : 0; - } - } - - public void show(Control source, Point location, IStructuredSelection selection) { - if (shell.isDisposed()) { - shell = new Shell(Display.getCurrent(), SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP); - createControl(); - } - if (shell.isVisible()) - shell.setVisible(false); - - if (aboutToShow(source, location, selection)) { - shell.pack(); - shell.layout(); - if (source instanceof Control) - shell.setLocation(((Control) source).toDisplay(location.x, location.y)); - shell.open(); - } - } - - protected Shell getParentShell() { - return parentShell; - } - - class StyleButton extends Label { - private static final long serialVersionUID = 7731102609123946115L; - - public StyleButton(Composite parent, int swtStyle) { - super(parent, swtStyle); - } - } - - class ActionsSelListener extends SelectionAdapter { - private static final long serialVersionUID = -1041871937815812149L; - - @Override - public void widgetSelected(SelectionEvent e) { - Object eventSource = e.getSource(); - if (eventSource instanceof Button) { - Button pressedBtn = (Button) eventSource; - performAction((String) pressedBtn.getData(KEY_ACTION_ID)); - shell.close(); - } - } - } - - class ActionsShellListener extends org.eclipse.swt.events.ShellAdapter { - private static final long serialVersionUID = -5092341449523150827L; - - @Override - public void shellDeactivated(ShellEvent e) { - setVisible(false); - shell.setVisible(false); - //shell.close(); - } - } - - protected abstract boolean performAction(String actionId); - - protected abstract boolean aboutToShow(Control source, Point location, IStructuredSelection selection); - - protected abstract String getLabel(String actionId); -}