Search in sources :

Example 1 with ControlSystemDragSource

use of org.csstudio.ui.util.dnd.ControlSystemDragSource in project org.csstudio.display.builder by kasemir.

the class SearchView method configureActions.

/**
 * React to selections, button presses, ...
 */
private void configureActions() {
    // Start a channel search
    search.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            searchForChannels();
        }
    });
    // Channel Table: Allow dragging of PVs with archive
    final Table table = channel_table.getTable();
    new ControlSystemDragSource(table) {

        @Override
        public Object getSelection() {
            final IStructuredSelection selection = (IStructuredSelection) channel_table.getSelection();
            // To allow transfer of array, the data must be
            // of the actual array type, not Object[]
            final Object[] objs = selection.toArray();
            final ChannelInfo[] channels = Arrays.copyOf(objs, objs.length, ChannelInfo[].class);
            return channels;
        }
    };
    // Double-clicks should have the same effect as context menu -> Data Browser
    getSite().setSelectionProvider(channel_table);
    channel_table.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            // casting is needed for RAP
            IHandlerService handlerService = getSite().getService(IHandlerService.class);
            try {
                handlerService.executeCommand("org.csstudio.trends.databrowser3.OpenDataBrowserPopup", null);
            } catch (CommandException ex) {
                // $NON-NLS-1$
                Activator.getLogger().log(Level.WARNING, "Failed to open data browser", ex);
            }
        }
    });
    // Add context menu for object contributions
    final MenuManager menu = new MenuManager();
    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    table.setMenu(menu.createContextMenu(table));
    getSite().registerContextMenu(menu, channel_table);
}
Also used : Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CommandException(org.eclipse.core.commands.common.CommandException) ControlSystemDragSource(org.csstudio.ui.util.dnd.ControlSystemDragSource) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuManager(org.eclipse.jface.action.MenuManager) Separator(org.eclipse.jface.action.Separator)

Example 2 with ControlSystemDragSource

use of org.csstudio.ui.util.dnd.ControlSystemDragSource in project org.csstudio.display.builder by kasemir.

the class DataBrowserPropertySheetPage method createTracesTabItemPanel.

/**
 * Within SashForm of the "Traces" tab, create the Model Item table
 *  @param sashform
 */
private void createTracesTabItemPanel(final SashForm sashform) {
    // TableColumnLayout requires the TableViewer to be in its own Composite!
    final Composite model_item_top = new Composite(sashform, SWT.BORDER);
    final TableColumnLayout table_layout = new MinSizeTableColumnLayout(10);
    model_item_top.setLayout(table_layout);
    // Would like to _not_ use FULL_SELECTION so that only the currently selected
    // cell gets highlighted, allowing the 'color' to still be visible
    // -> On Linux, you only get FULL_SELECTION behavior.
    // -> On Windows, editing is really odd, need to select a column before anything
    // can be edited, plus color still invisible
    // ---> Using FULL_SELECTION
    trace_table = new TableViewer(model_item_top, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    final Table table = trace_table.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    final TraceTableHandler tth = new TraceTableHandler();
    tth.createColumns(table_layout, operations_manager, trace_table);
    trace_table.setContentProvider(tth);
    trace_table.setInput(model);
    new ControlSystemDragSource(trace_table.getControl()) {

        @Override
        public Object getSelection() {
            final IStructuredSelection selection = (IStructuredSelection) trace_table.getSelection();
            final Object[] objs = selection.toArray();
            final ModelItem[] items = Arrays.copyOf(objs, objs.length, ModelItem[].class);
            return items;
        }
    };
}
Also used : ControlSystemDragSource(org.csstudio.ui.util.dnd.ControlSystemDragSource) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) MinSizeTableColumnLayout(org.csstudio.ui.util.MinSizeTableColumnLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ControlSystemDragSource (org.csstudio.ui.util.dnd.ControlSystemDragSource)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Table (org.eclipse.swt.widgets.Table)2 ChannelInfo (org.csstudio.trends.databrowser3.model.ChannelInfo)1 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)1 MinSizeTableColumnLayout (org.csstudio.ui.util.MinSizeTableColumnLayout)1 CommandException (org.eclipse.core.commands.common.CommandException)1 MenuManager (org.eclipse.jface.action.MenuManager)1 Separator (org.eclipse.jface.action.Separator)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Composite (org.eclipse.swt.widgets.Composite)1 IHandlerService (org.eclipse.ui.handlers.IHandlerService)1