Search in sources :

Example 36 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project tdi-studio-se by Talend.

the class TalendTabbedPropertySheetPage method selectionChanged.

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    ISelection newSelection;
    if (part instanceof AbstractMultiPageTalendEditor) {
        AbstractMultiPageTalendEditor mpte = (AbstractMultiPageTalendEditor) part;
        newSelection = mpte.getTalendEditor().getViewer().getSelection();
        if (selection instanceof StructuredSelection) {
            StructuredSelection structSel = (StructuredSelection) newSelection;
            if (structSel.size() != 1) {
                return;
            }
            if (structSel.getFirstElement() instanceof EditPart) {
                if (structSel.equals(oldSelection)) {
                // if (getCurrentTab() != null) {
                // getCurrentTab().setInput(part, selection);
                // }
                } else {
                    super.selectionChanged(part, selection);
                }
                oldSelection = structSel;
            }
        }
    } else if (part instanceof ContentOutline) {
        ContentOutline outline = (ContentOutline) part;
        newSelection = outline.getSelection();
        if (selection instanceof StructuredSelection) {
            StructuredSelection structSel = (StructuredSelection) newSelection;
            if (structSel.size() != 1) {
                return;
            }
            if (structSel.getFirstElement() instanceof NodeTreeEditPart) {
                if (structSel.equals(oldSelection)) {
                // this.getCurrentTab().setInput(part, selection);
                } else {
                    super.selectionChanged(part, selection);
                }
                oldSelection = structSel;
            }
        }
    }
}
Also used : NodeTreeEditPart(org.talend.designer.core.ui.editor.outline.NodeTreeEditPart) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) NodeTreeEditPart(org.talend.designer.core.ui.editor.outline.NodeTreeEditPart) EditPart(org.eclipse.gef.EditPart) ContentOutline(org.eclipse.ui.views.contentoutline.ContentOutline)

Example 37 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project tdi-studio-se by Talend.

the class TalendSelectionManager method setSelection.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.SelectionManager#setSelection(org.eclipse.jface.viewers.ISelection)
     */
@Override
public void setSelection(ISelection arg0) {
    if (arg0 instanceof StructuredSelection) {
        StructuredSelection selection = filterSelection((StructuredSelection) arg0);
        if (selection.size() != 1) {
            // if there is more than one element, remove all the selections of labels
            if (selection.size() > 1) {
                this.selectionType = ETalendSelectionType.MULTIPLE;
            } else {
                this.selectionType = ETalendSelectionType.NONE;
            }
            super.setSelection(selection);
        } else {
            this.selectionType = ETalendSelectionType.SINGLE;
            super.setSelection(selection);
        }
    } else {
        this.selectionType = ETalendSelectionType.SINGLE;
        super.setSelection(arg0);
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 38 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project tdi-studio-se by Talend.

the class TalendSelectionManager method appendSelection.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.SelectionManager#appendSelection(org.eclipse.gef.EditPart)
     */
@Override
public void appendSelection(EditPart arg0) {
    // judge whether the refresh operation is executed.
    // see bug 3315.
    boolean needRefresh = false;
    if (getSelection() instanceof StructuredSelection) {
        StructuredSelection selection = (StructuredSelection) getSelection();
        Object selected = null;
        for (Object element : selection.toArray()) {
            selected = element;
        }
        if (getSelection().isEmpty() || (selected instanceof ProcessPart)) {
            this.selectionType = ETalendSelectionType.SINGLE;
            needRefresh = true;
        }
        if (!(arg0 instanceof NodeLabelEditPart) && !(arg0 instanceof ConnLabelEditPart) && !(arg0 instanceof ConnectionPart)) {
            // removes old selections of labels by calling setSelection
            for (Object element : selection.toArray()) {
                if (element instanceof NodeLabelEditPart) {
                    this.deselect(((AbstractGraphicalEditPart) element));
                } else if (element instanceof ConnLabelEditPart) {
                    this.deselect(((AbstractGraphicalEditPart) element));
                } else if (element instanceof ConnectionPart) {
                    this.deselect(((AbstractConnectionEditPart) element));
                }
            }
            needRefresh = true;
        }
        if (arg0 instanceof ConnectionPerformanceEditPart && getSelectPoint() != null) {
            if (needRefresh) {
                EditPart transferPart = transferFocus((ConnectionPerformanceEditPart) arg0);
                if (transferPart == null) {
                    needRefresh = false;
                    setSelectPoint(null);
                    return;
                }
                super.appendSelection(transferPart);
                needRefresh = false;
                return;
            }
        }
        if (needRefresh) {
            super.appendSelection(arg0);
            needRefresh = false;
            setSelectPoint(null);
        }
    }
}
Also used : AbstractConnectionEditPart(org.eclipse.gef.editparts.AbstractConnectionEditPart) ConnectionPerformanceEditPart(org.talend.designer.core.ui.editor.connections.ConnectionPerformanceEditPart) AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) EditPart(org.eclipse.gef.EditPart) AbstractConnectionEditPart(org.eclipse.gef.editparts.AbstractConnectionEditPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) ConnectionPerformanceEditPart(org.talend.designer.core.ui.editor.connections.ConnectionPerformanceEditPart) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 39 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project tdi-studio-se by Talend.

the class BusinessAssignmentComposite method createSelectionListener.

private void createSelectionListener() {
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            BusinessAssignment businessAssignment = getBusinessAssignment(event.getSelection());
            if (businessAssignment != null) {
                final IRepositoryView repositoryView = getRepositoryView();
                if (repositoryView != null) {
                    IProjectRepositoryNode rootRepositoryNode = repositoryView.getRoot();
                    TalendItem item = businessAssignment.getTalendItem();
                    //
                    if (item instanceof Routine && rootRepositoryNode instanceof ProjectRepositoryNode) {
                        RepositoryNodeUtilities.expandParentNode(getRepositoryView(), ((ProjectRepositoryNode) rootRepositoryNode).getRootRepositoryNode(ERepositoryObjectType.CODE));
                    }
                    selectChild(item, (IRepositoryNode) rootRepositoryNode);
                }
            }
        }

        private void selectChild(TalendItem item, IRepositoryNode rootRepositoryNode) {
            try {
                RepositoryNode curNode = null;
                JobSettingsView viewer = (JobSettingsView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(JobSettingsView.ID);
                IRepositoryViewObject lastVersion = ProxyRepositoryFactory.getInstance().getLastVersion(item.getId());
                if (lastVersion != null) {
                    curNode = RepositoryNodeUtilities.getRepositoryNode(lastVersion);
                    select(viewer, curNode);
                } else if (item instanceof TableMetadata) {
                    MetadataTable table = MetadataToolHelper.getMetadataTableFromRepository(item.getId());
                    if (table != null) {
                        //$NON-NLS-1$
                        String id = item.getId().split(" - ")[0];
                        RepositoryNode node = RepositoryNodeUtilities.getMetadataTableFromConnection(item.getId());
                        IRepositoryView view = getRepositoryView();
                        if (view != null) {
                            RepositoryNodeUtilities.expandParentNode(view, node);
                            select(viewer, node);
                        }
                    }
                } else if (item instanceof Query) {
                    org.talend.core.model.metadata.builder.connection.Query query = MetadataToolHelper.getQueryFromRepository(item.getId());
                    if (query != null) {
                        //$NON-NLS-1$
                        String id = item.getId().split(" - ")[0];
                        IRepositoryView view = getRepositoryView();
                        RepositoryNode node = RepositoryNodeUtilities.getQueryFromConnection(item.getId());
                        RepositoryNodeUtilities.expandParentNode(view, node);
                        select(viewer, node);
                    }
                } else if (item instanceof SAPFunction) {
                    SAPFunctionUnit function = MetadataToolHelper.getSAPFunctionFromRepository(item.getId());
                    if (function != null) {
                        IRepositoryView view = getRepositoryView();
                        RepositoryNode node = RepositoryNodeUtilities.getSAPFunctionFromConnection(item.getId());
                        RepositoryNodeUtilities.expandParentNode(view, node);
                        select(viewer, node);
                    }
                } else {
                    for (IRepositoryNode node : rootRepositoryNode.getChildren()) {
                        RepositoryNode rNode = (RepositoryNode) node;
                        if (item instanceof SQLPattern && rNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.SQLPATTERNS) {
                            if (rNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
                                SQLPatternItem sqlItem = (SQLPatternItem) rNode.getObject().getProperty().getItem();
                                if (sqlItem.isSystem() && item.getLabel().equals(rNode.getObject().getLabel())) {
                                    select(viewer, rNode);
                                }
                            } else {
                                selectChild(item, rNode);
                            }
                        } else if (item instanceof Routine && rNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.ROUTINES) {
                            if (rNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
                                RoutineItem sqlItem = (RoutineItem) rNode.getObject().getProperty().getItem();
                                if (sqlItem.isBuiltIn() && item.getLabel().equals(rNode.getObject().getLabel())) {
                                    select(viewer, rNode);
                                }
                            } else {
                                selectChild(item, rNode);
                            }
                        }
                    }
                }
            } catch (PersistenceException e) {
                // TODO Auto-generated catch block
                // e.printStackTrace();
                ExceptionHandler.process(e);
            }
        }

        private void select(JobSettingsView viewer, RepositoryNode repositoryNode) {
            if (viewer == null) {
                return;
            }
            if (repositoryNode == null) {
                return;
            }
            CorePlugin.getDefault().getRepositoryService().removeRepositoryTreeViewListener(viewer);
            final IRepositoryView repositoryView = getRepositoryView();
            if (repositoryView != null) {
                repositoryView.getViewer().setSelection(new StructuredSelection(repositoryNode));
            }
            CorePlugin.getDefault().getRepositoryService().addRepositoryTreeViewListener(viewer);
        }
    });
}
Also used : JobSettingsView(org.talend.designer.core.ui.views.jobsettings.JobSettingsView) BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) Query(org.talend.designer.business.model.business.Query) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) TalendItem(org.talend.designer.business.model.business.TalendItem) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) TableMetadata(org.talend.designer.business.model.business.TableMetadata) SAPFunction(org.talend.designer.business.model.business.SAPFunction) SQLPattern(org.talend.designer.business.model.business.SQLPattern) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) RoutineItem(org.talend.core.model.properties.RoutineItem) Routine(org.talend.designer.business.model.business.Routine) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 40 with StructuredSelection

use of org.eclipse.jface.viewers.StructuredSelection in project tdi-studio-se by Talend.

the class AssignmentPropertySection method createPopupMenu.

private void createPopupMenu() {
    //$NON-NLS-1$
    MenuManager menuMgr = new MenuManager("#PopUp");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager mgr) {
            BusinessAssignment businessAssignment = getBusinessAssignment(tableViewer.getSelection());
            if (businessAssignment != null) {
                repositoryNode = createRepositoryNode(businessAssignment);
                if (repositoryNode != null) {
                    List<ITreeContextualAction> contextualsActions = ActionsHelper.getRepositoryContextualsActions();
                    for (ITreeContextualAction action : contextualsActions) {
                        if (action.isReadAction() || action.isEditAction() || action.isPropertiesAction()) {
                            action.init(null, new StructuredSelection(repositoryNode));
                            if (action.isVisible()) {
                                mgr.add(action);
                            }
                        }
                    }
                }
            }
        }
    });
    Menu menu = menuMgr.createContextMenu(tableViewer.getControl());
    tableViewer.getControl().setMenu(menu);
}
Also used : BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) List(java.util.List) ArrayList(java.util.ArrayList) IMenuManager(org.eclipse.jface.action.IMenuManager) ITreeContextualAction(org.talend.commons.ui.swt.actions.ITreeContextualAction) Menu(org.eclipse.swt.widgets.Menu) IMenuListener(org.eclipse.jface.action.IMenuListener)

Aggregations

StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1376 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)782 ArrayList (java.util.ArrayList)212 ISelection (org.eclipse.jface.viewers.ISelection)177 Composite (org.eclipse.swt.widgets.Composite)167 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)133 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)128 GridData (org.eclipse.swt.layout.GridData)112 List (java.util.List)93 IFile (org.eclipse.core.resources.IFile)92 GridLayout (org.eclipse.swt.layout.GridLayout)87 SelectionEvent (org.eclipse.swt.events.SelectionEvent)82 Label (org.eclipse.swt.widgets.Label)79 TreeViewer (org.eclipse.jface.viewers.TreeViewer)78 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)68 EObject (org.eclipse.emf.ecore.EObject)67 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)66 TableViewer (org.eclipse.jface.viewers.TableViewer)64 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)61 AdapterFactoryContentProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider)60