Search in sources :

Example 1 with VarToolBarFigure

use of org.talend.designer.xmlmap.figures.treetools.VarToolBarFigure in project tdi-studio-se by Talend.

the class XmlMapVarTablePart method activate.

@Override
public void activate() {
    super.activate();
    selectionListener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            List selectedEditParts = getViewer().getSelectedEditParts();
            boolean remove = false;
            boolean moveUp = false;
            boolean moveDown = false;
            boolean disableMoveUp = false;
            boolean disableMoveDown = false;
            for (Object obj : selectedEditParts) {
                if (obj instanceof VarNodeEditPart) {
                    remove = true;
                    VarNode selectedNode = (VarNode) ((VarNodeEditPart) obj).getModel();
                    EList<VarNode> nodes = ((VarTable) getModel()).getNodes();
                    int indexOf = nodes.indexOf(selectedNode);
                    if (!disableMoveUp) {
                        if (indexOf != -1 && indexOf > 0) {
                            moveUp = true;
                        } else {
                            moveUp = false;
                            disableMoveUp = true;
                        }
                    }
                    if (!disableMoveDown) {
                        if (indexOf != -1 && indexOf < nodes.size() - 1) {
                            moveDown = true;
                        } else {
                            moveDown = false;
                            disableMoveDown = true;
                        }
                    }
                }
            }
            VarToolBarFigure toolBarFigure = ((VarTableContainer) getFigure()).getToolBarFigure();
            toolBarFigure.setRemoveEnable(remove);
            toolBarFigure.setMoveUpEnable(moveUp);
            toolBarFigure.setMoveDownEnable(moveDown);
        }
    };
    getViewer().addSelectionChangedListener(selectionListener);
}
Also used : VarNode(org.talend.designer.xmlmap.model.emf.xmlmap.VarNode) VarToolBarFigure(org.talend.designer.xmlmap.figures.treetools.VarToolBarFigure) EList(org.eclipse.emf.common.util.EList) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) EList(org.eclipse.emf.common.util.EList) List(java.util.List)

Aggregations

List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 VarToolBarFigure (org.talend.designer.xmlmap.figures.treetools.VarToolBarFigure)1 VarNode (org.talend.designer.xmlmap.model.emf.xmlmap.VarNode)1