Search in sources :

Example 1 with ISelectionListener

use of org.eclipse.ui.ISelectionListener in project sling by apache.

the class JcrPropertiesView method createPartControl.

/**
	 * This is a callback that will allow us
	 * to create the viewer and initialize it.
	 */
public void createPartControl(Composite parent) {
    SyncDirManager.registerUpdateListener(new UpdateHandler() {

        @Override
        public void syncDirUpdated(SyncDir syncDir) {
            refreshContent();
        }
    });
    mainControl = new Composite(parent, SWT.NONE);
    final GridLayout gridLayout = new GridLayout(1, true);
    mainControl.setLayout(gridLayout);
    if (getViewSite() != null) {
        titleLabel = new Label(mainControl, SWT.WRAP);
        titleLabel.setText("");
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
        titleLabel.setLayoutData(data);
        Label horizontalLine = new Label(mainControl, SWT.SEPARATOR | SWT.HORIZONTAL);
        data = new GridData(GridData.FILL_HORIZONTAL);
        horizontalLine.setLayoutData(data);
    }
    Font font;
    if (!JFaceResources.getFontRegistry().hasValueFor(TITLE_FONT)) {
        FontData[] fontData = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT).getFontData();
        /* title font is 2pt larger than that used in the tabs. */
        fontData[0].setHeight(fontData[0].getHeight() + 2);
        JFaceResources.getFontRegistry().put(TITLE_FONT, fontData);
    }
    font = JFaceResources.getFont(TITLE_FONT);
    if (titleLabel != null) {
        titleLabel.setFont(font);
    }
    Composite tableParent = new Composite(mainControl, SWT.NONE);
    //        tableParent.setBackground(new Color(Display.getDefault(), 100,20,180));
    GridData tableLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    // shrink to min - table settings will resize to correct ratios
    tableLayoutData.widthHint = 1;
    tableLayoutData.heightHint = SWT.DEFAULT;
    tableParent.setLayoutData(tableLayoutData);
    TableColumnLayout tableLayout = new TableColumnLayout() {

        @Override
        protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
            Point p = super.computeSize(composite, wHint, hHint, flushCache);
            return new Point(p.x, p.y);
        }
    };
    tableParent.setLayout(tableLayout);
    viewer = new TableViewer(tableParent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.HIDE_SELECTION | SWT.FULL_SELECTION);
    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter(viewer), new CellNavigationStrategy());
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            resetLastValueEdited();
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    int features = ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK;
    TableViewerEditor.create(viewer, focusCellManager, actSupport, features);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    viewer.setContentProvider(new ViewContentProvider());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            final ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection iss = (IStructuredSelection) selection;
                if (iss.isEmpty()) {
                    deleteAction.setEnabled(false);
                } else {
                    deleteAction.setEnabled(true);
                }
            } else {
                deleteAction.setEnabled(false);
            }
        }
    });
    CellLabelProvider clp = new JcrCellLabelProvider(viewer);
    TableViewerColumn column0 = new TableViewerColumn(viewer, SWT.NONE);
    column0.getColumn().setText("Name");
    column0.getColumn().setResizable(true);
    column0.getColumn().setWidth(200);
    tableLayout.setColumnData(column0.getColumn(), new ColumnWeightData(30, 140));
    final TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
    column1.getColumn().setText("Type");
    column1.getColumn().setResizable(true);
    column1.getColumn().setWidth(300);
    column1.setLabelProvider(clp);
    tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(10, 80));
    final TableViewerColumn column2 = new TableViewerColumn(viewer, SWT.NONE);
    column2.getColumn().setText("Value");
    column2.getColumn().setResizable(true);
    column2.getColumn().setWidth(300);
    tableLayout.setColumnData(column2.getColumn(), new ColumnWeightData(70, 220));
    final TableViewerColumn column3 = new TableViewerColumn(viewer, SWT.NONE);
    column3.getColumn().setText("Protected");
    column3.getColumn().setResizable(true);
    column3.getColumn().setWidth(300);
    column3.setLabelProvider(clp);
    tableLayout.setColumnData(column3.getColumn(), new ColumnWeightData(5, 57));
    final TableViewerColumn column4 = new TableViewerColumn(viewer, SWT.NONE);
    column4.getColumn().setText("Mandatory");
    column4.getColumn().setResizable(true);
    column4.getColumn().setWidth(300);
    column4.setLabelProvider(clp);
    tableLayout.setColumnData(column4.getColumn(), new ColumnWeightData(5, 62));
    final TableViewerColumn column5 = new TableViewerColumn(viewer, SWT.NONE);
    column5.getColumn().setText("Multiple");
    column5.getColumn().setResizable(true);
    column5.getColumn().setWidth(300);
    column5.setLabelProvider(clp);
    tableLayout.setColumnData(column5.getColumn(), new ColumnWeightData(5, 82));
    final TableViewerColumn column6 = new TableViewerColumn(viewer, SWT.NONE);
    column6.getColumn().setText("Auto Created");
    column6.getColumn().setResizable(true);
    column6.getColumn().setWidth(300);
    column6.setLabelProvider(clp);
    tableLayout.setColumnData(column6.getColumn(), new ColumnWeightData(5, 77));
    column0.setLabelProvider(clp);
    column0.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.NAME));
    column1.setLabelProvider(clp);
    column1.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.TYPE));
    column2.setLabelProvider(clp);
    column2.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.VALUE));
    column5.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.MULTIPLE));
    // Create the help context id for the viewer's control
    PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.apache.sling.ide.eclipse-ui.viewer");
    makeActions();
    hookContextMenu();
    hookDoubleClickAction();
    contributeToActionBars();
    listener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection iss = (IStructuredSelection) selection;
                Object firstElem = iss.getFirstElement();
                if (firstElem instanceof JcrNode) {
                    JcrNode jcrNode = (JcrNode) firstElem;
                    setInput(jcrNode);
                    return;
                }
            }
        }
    };
    if (getViewSite() != null) {
        getViewSite().getPage().addSelectionListener(listener);
        final ISelection selection = getViewSite().getPage().getSelection();
        Display.getCurrent().asyncExec(new Runnable() {

            @Override
            public void run() {
                listener.selectionChanged(null, selection);
            }
        });
    }
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Label(org.eclipse.swt.widgets.Label) SyncDir(org.apache.sling.ide.eclipse.ui.nav.model.SyncDir) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Font(org.eclipse.swt.graphics.Font) ISelectionListener(org.eclipse.ui.ISelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) FocusCellOwnerDrawHighlighter(org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) UpdateHandler(org.apache.sling.ide.eclipse.ui.nav.model.UpdateHandler) Composite(org.eclipse.swt.widgets.Composite) FontData(org.eclipse.swt.graphics.FontData) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Point(org.eclipse.swt.graphics.Point) CellNavigationStrategy(org.eclipse.jface.viewers.CellNavigationStrategy) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) Point(org.eclipse.swt.graphics.Point) TableViewerFocusCellManager(org.eclipse.jface.viewers.TableViewerFocusCellManager) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 2 with ISelectionListener

use of org.eclipse.ui.ISelectionListener in project eclipse-cs by checkstyle.

the class AbstractStatsView method createPartControl.

// 
// methods
// 
/**
 * {@inheritDoc}
 *
 * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createPartControl(Composite parent) {
    mMainComposite = parent;
    // create and register the workspace focus listener
    mFocusListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            AbstractStatsView.this.focusSelectionChanged(part, selection);
        }
    };
    getSite().getPage().addSelectionListener(mFocusListener);
    focusSelectionChanged(getSite().getPage().getActivePart(), getSite().getPage().getSelection());
    // create and register the listener for resource changes
    mResourceListener = new IResourceChangeListener() {

        @Override
        public void resourceChanged(IResourceChangeEvent event) {
            IMarkerDelta[] markerDeltas = event.findMarkerDeltas(CheckstyleMarker.MARKER_ID, true);
            if (markerDeltas.length > 0) {
                refresh();
            }
        }
    };
    ResourcesPlugin.getWorkspace().addResourceChangeListener(mResourceListener);
    makeActions();
    initActionBars(getViewSite().getActionBars());
}
Also used : IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ISelectionListener(org.eclipse.ui.ISelectionListener)

Example 3 with ISelectionListener

use of org.eclipse.ui.ISelectionListener in project egit by eclipse.

the class RebaseInteractiveView method setupRepositoryViewSelectionChangeListener.

private void setupRepositoryViewSelectionChangeListener() {
    selectionChangedListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (!listenOnRepositoryViewSelection || part == getSite().getPart()) {
                return;
            }
            // this may happen if we switch between editors
            if (part instanceof IEditorPart) {
                IEditorInput input = ((IEditorPart) part).getEditorInput();
                if (input instanceof IFileEditorInput) {
                    newInput(new StructuredSelection(((IFileEditorInput) input).getFile()), false);
                }
            } else {
                newInput(selection, false);
            }
        }
    };
    ISelectionService srv = CommonUtils.getService(getSite(), ISelectionService.class);
    srv.addPostSelectionListener(selectionChangedListener);
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IFileEditorInput(org.eclipse.ui.IFileEditorInput) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelectionService(org.eclipse.ui.ISelectionService) IEditorPart(org.eclipse.ui.IEditorPart) ISelectionListener(org.eclipse.ui.ISelectionListener) IEditorInput(org.eclipse.ui.IEditorInput)

Example 4 with ISelectionListener

use of org.eclipse.ui.ISelectionListener in project netxms by netxms.

the class ReportView method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    this.parentComposite = parent;
    selectionService = getSite().getWorkbenchWindow().getSelectionService();
    selectionListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if ((part instanceof ReportNavigator) && (selection instanceof IStructuredSelection) && !selection.isEmpty()) {
                ReportDefinition object = (ReportDefinition) ((IStructuredSelection) selection).getFirstElement();
                setObject(object);
            }
        }
    };
    selectionService.addSelectionListener(selectionListener);
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelectionListener(org.eclipse.ui.ISelectionListener) ReportDefinition(org.netxms.client.reporting.ReportDefinition)

Example 5 with ISelectionListener

use of org.eclipse.ui.ISelectionListener in project netxms by netxms.

the class TabbedObjectView method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    parent.setLayout(layout);
    headerFont = FontTools.createFont(HEADER_FONTS, +3, SWT.BOLD);
    header = new CLabel(parent, SWT.BORDER);
    header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    header.setFont(headerFont);
    header.setBackground(SharedColors.getColor(SharedColors.OBJECT_TAB_HEADER_BACKGROUND, parent.getDisplay()));
    header.setForeground(SharedColors.getColor(SharedColors.OBJECT_TAB_HEADER, parent.getDisplay()));
    tabFolder = new CTabFolder(parent, SWT.TOP | SWT.FLAT | SWT.MULTI);
    tabFolder.setUnselectedImageVisible(true);
    tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    tabFolder.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            onTabSelectionChange((e.item != null) ? (ObjectTab) ((CTabItem) e.item).getData() : null);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    tabs = new ArrayList<ObjectTab>();
    addTabs();
    selectionListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (// $NON-NLS-1$
            (part.getSite().getId().equals("org.netxms.ui.eclipse.view.navigation.objectbrowser")) && (selection instanceof IStructuredSelection)) {
                if (selection.isEmpty()) {
                    setObject(null);
                } else {
                    Object object = ((IStructuredSelection) selection).getFirstElement();
                    if (object instanceof AbstractObject) {
                        setObject((AbstractObject) object);
                    }
                }
            }
        }
    };
    selectionService.addPostSelectionListener(selectionListener);
    createActions();
    contributeToActionBars();
    selectionProvider = new IntermediateSelectionProvider();
    getSite().setSelectionProvider(selectionProvider);
    final NXCSession session = ConsoleSharedData.getSession();
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if ((n.getCode() == SessionNotification.OBJECT_CHANGED) && (objectId == n.getSubCode())) {
                final AbstractObject object = (AbstractObject) n.getObject();
                getSite().getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        onObjectUpdate(object);
                    }
                });
            }
        }
    };
    session.addListener(sessionListener);
    CommandBridge.getInstance().registerCommand("TabbedObjectView/selectTab", new // $NON-NLS-1$
    Command() {

        @Override
        public Object execute(String name, Object arg) {
            if (arg instanceof String)
                selectTab((String) arg);
            return null;
        }
    });
    CommandBridge.getInstance().registerCommand("TabbedObjectView/changeObject", new // $NON-NLS-1$
    Command() {

        @Override
        public Object execute(String name, Object arg) {
            if (arg instanceof Long)
                setObject(session.findObjectById((Long) arg));
            return null;
        }
    });
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) IntermediateSelectionProvider(org.netxms.ui.eclipse.tools.IntermediateSelectionProvider) CTabFolder(org.eclipse.swt.custom.CTabFolder) NXCSession(org.netxms.client.NXCSession) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CTabItem(org.eclipse.swt.custom.CTabItem) ISelectionListener(org.eclipse.ui.ISelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AbstractObject(org.netxms.client.objects.AbstractObject) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) AbstractObject(org.netxms.client.objects.AbstractObject) SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification) ObjectTab(org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab) ISelectionListener(org.eclipse.ui.ISelectionListener) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ISelectionListener (org.eclipse.ui.ISelectionListener)15 ISelection (org.eclipse.jface.viewers.ISelection)12 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)11 Composite (org.eclipse.swt.widgets.Composite)6 TreeViewer (org.eclipse.jface.viewers.TreeViewer)4 ArrayList (java.util.ArrayList)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 IEditorInput (org.eclipse.ui.IEditorInput)3 ISelectionService (org.eclipse.ui.ISelectionService)3 Cell (eu.esdihumboldt.hale.common.align.model.Cell)2 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)2 ResolvedTask (eu.esdihumboldt.hale.common.tasks.ResolvedTask)2 TaskService (eu.esdihumboldt.hale.common.tasks.TaskService)2 TaskServiceListener (eu.esdihumboldt.hale.common.tasks.TaskServiceListener)2 SchemaSelection (eu.esdihumboldt.hale.ui.selection.SchemaSelection)2 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)2 AlignmentServiceAdapter (eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter)2 PropertiesViewPart (eu.esdihumboldt.hale.ui.views.properties.PropertiesViewPart)2 Map (java.util.Map)2