Search in sources :

Example 1 with ElementAction

use of org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementAction in project egit by eclipse.

the class RebaseInteractiveStepActionToolBarProvider method mapActionItemsToSelection.

void mapActionItemsToSelection(ISelection selection) {
    setMoveItemsEnabled(false);
    if (selection == null || selection.isEmpty()) {
        if (theToolbar.isEnabled())
            theToolbar.setEnabled(false);
        unselectAllActionItemsExecpt(null);
        return;
    }
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structured = (IStructuredSelection) selection;
        Object obj = structured.getFirstElement();
        if (!(obj instanceof PlanElement))
            return;
        PlanElement firstSelectedEntry = (PlanElement) obj;
        PlanElement lastSelectedEntry = firstSelectedEntry;
        ElementAction type = firstSelectedEntry.getPlanElementAction();
        boolean singleTypeSelected = true;
        if (!theToolbar.isEnabled() && !view.getCurrentPlan().hasRebaseBeenStartedYet())
            theToolbar.setEnabled(true);
        if (structured.size() > 1) {
            // multi selection
            for (Object selectedObj : structured.toList()) {
                if (!(selectedObj instanceof PlanElement))
                    continue;
                PlanElement entry = (PlanElement) selectedObj;
                lastSelectedEntry = entry;
                if (type != entry.getPlanElementAction()) {
                    singleTypeSelected = false;
                }
            }
        }
        if (singleTypeSelected)
            unselectAllActionItemsExecpt(type);
        else
            unselectAllActionItemsExecpt(null);
        enableMoveButtons(firstSelectedEntry, lastSelectedEntry);
    }
}
Also used : ElementAction(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PlanElement(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.PlanElement)

Example 2 with ElementAction

use of org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementAction in project egit by eclipse.

the class RebaseInteractiveView method createColumns.

private void createColumns(TreeColumnLayout layout) {
    String[] headings = { UIText.RebaseInteractiveView_HeadingStatus, UIText.RebaseInteractiveView_HeadingStep, UIText.RebaseInteractiveView_HeadingAction, UIText.RebaseInteractiveView_HeadingCommitId, UIText.RebaseInteractiveView_HeadingMessage, UIText.RebaseInteractiveView_HeadingAuthor, UIText.RebaseInteractiveView_HeadingAuthorDate, UIText.RebaseInteractiveView_HeadingCommitter, UIText.RebaseInteractiveView_HeadingCommitDate };
    ColumnViewerToolTipSupport.enableFor(planTreeViewer, ToolTip.NO_RECREATE);
    TreeViewerColumn infoColumn = createColumn(headings[0]);
    layout.setColumnData(infoColumn.getColumn(), new ColumnPixelData(70));
    infoColumn.setLabelProvider(new HighlightingColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            ElementType t = getType(element);
            if (t != null) {
                switch(t) {
                    case DONE_CURRENT:
                        return UIIcons.getImage(resources, UIIcons.CURRENT_STEP);
                    case DONE:
                        return UIIcons.getImage(resources, UIIcons.DONE_STEP);
                    default:
                }
            }
            return null;
        }

        @Override
        public String getToolTipText(Object element) {
            ElementType t = getType(element);
            if (t != null) {
                switch(t) {
                    case DONE:
                        return UIText.RebaseInteractiveView_StatusDone;
                    case DONE_CURRENT:
                        return UIText.RebaseInteractiveView_StatusCurrent;
                    case TODO:
                        return UIText.RebaseInteractiveView_StatusTodo;
                    default:
                }
            }
            // $NON-NLS-1$
            return "";
        }

        @Override
        public String getText(Object element) {
            // $NON-NLS-1$
            return "";
        }
    });
    TreeViewerColumn stepColumn = createColumn(headings[1]);
    layout.setColumnData(stepColumn.getColumn(), new ColumnPixelData(55));
    stepColumn.setLabelProvider(new HighlightingColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof PlanElement) {
                PlanElement planLine = (PlanElement) element;
                // $NON-NLS-1$
                return (planIndexer.indexOf(planLine) + 1) + ".";
            }
            return super.getText(element);
        }
    });
    stepColumn.getColumn().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Tree tree = planTreeViewer.getTree();
            boolean orderReversed = tree.getSortDirection() == SWT.DOWN;
            RebaseInteractivePreferences.setOrderReversed(!orderReversed);
            int newDirection = (orderReversed ? SWT.UP : SWT.DOWN);
            tree.setSortDirection(newDirection);
            TreeItem topmostVisibleItem = tree.getTopItem();
            refreshUI();
            if (topmostVisibleItem != null)
                tree.showItem(topmostVisibleItem);
        }
    });
    int direction = (RebaseInteractivePreferences.isOrderReversed() ? SWT.DOWN : SWT.UP);
    Tree planTree = planTreeViewer.getTree();
    planTree.setSortColumn(stepColumn.getColumn());
    planTree.setSortDirection(direction);
    TreeViewerColumn actionColumn = createColumn(headings[2]);
    layout.setColumnData(actionColumn.getColumn(), new ColumnPixelData(90));
    actionColumn.setLabelProvider(new HighlightingColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            ElementAction a = getAction(element);
            if (a != null) {
                switch(a) {
                    case EDIT:
                        return UIIcons.getImage(resources, UIIcons.EDITCONFIG);
                    case FIXUP:
                        if (RebaseInteractivePreferences.isOrderReversed())
                            return UIIcons.getImage(resources, UIIcons.FIXUP_DOWN);
                        else
                            return UIIcons.getImage(resources, UIIcons.FIXUP_UP);
                    case PICK:
                        return UIIcons.getImage(resources, UIIcons.CHERRY_PICK);
                    case REWORD:
                        return UIIcons.getImage(resources, UIIcons.REWORD);
                    case SKIP:
                        return UIIcons.getImage(resources, UIIcons.REBASE_SKIP);
                    case SQUASH:
                        if (RebaseInteractivePreferences.isOrderReversed())
                            return UIIcons.getImage(resources, UIIcons.SQUASH_DOWN);
                        else
                            return UIIcons.getImage(resources, UIIcons.SQUASH_UP);
                    default:
                }
            }
            return super.getImage(element);
        }

        @Override
        public String getText(Object element) {
            ElementAction a = getAction(element);
            return (a != null) ? a.name() : super.getText(element);
        }

        private ElementAction getAction(Object element) {
            if (element instanceof PlanElement) {
                PlanElement planLine = (PlanElement) element;
                return planLine.getPlanElementAction();
            } else
                return null;
        }
    });
    TreeViewerColumn commitIDColumn = createColumn(headings[3]);
    int minWidth;
    GC gc = new GC(planTreeViewer.getControl().getDisplay());
    try {
        gc.setFont(planTreeViewer.getControl().getFont());
        minWidth = // $NON-NLS-1$
        Math.max(// $NON-NLS-1$
        gc.stringExtent("0000000").x, gc.stringExtent(headings[3]).x) + 10;
    } finally {
        gc.dispose();
    }
    layout.setColumnData(commitIDColumn.getColumn(), new ColumnPixelData(minWidth));
    commitIDColumn.setLabelProvider(new HighlightingColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof PlanElement) {
                PlanElement planLine = (PlanElement) element;
                return planLine.getCommit().name();
            }
            return super.getText(element);
        }
    });
    TreeViewerColumn commitMessageColumn = createColumn(headings[4]);
    layout.setColumnData(commitMessageColumn.getColumn(), new ColumnWeightData(200, 200));
    commitMessageColumn.setLabelProvider(new HighlightingColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof PlanElement) {
                PlanElement planLine = (PlanElement) element;
                return planLine.getShortMessage();
            }
            return super.getText(element);
        }
    });
    TreeViewerColumn authorColumn = createColumn(headings[5]);
    layout.setColumnData(authorColumn.getColumn(), new ColumnWeightData(120, 120));
    authorColumn.setLabelProvider(new HighlightingColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof PlanElement) {
                PlanElement planLine = (PlanElement) element;
                return planLine.getAuthor();
            }
            return super.getText(element);
        }
    });
    TreeViewerColumn authoredDateColumn = createColumn(headings[6]);
    layout.setColumnData(authoredDateColumn.getColumn(), new ColumnWeightData(80, 80));
    authoredDateColumn.setLabelProvider(new HighlightingColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof PlanElement) {
                PlanElement planLine = (PlanElement) element;
                return planLine.getAuthoredDate(dateFormatter);
            }
            return super.getText(element);
        }
    });
    TreeViewerColumn committerColumn = createColumn(headings[7]);
    layout.setColumnData(committerColumn.getColumn(), new ColumnWeightData(120, 120));
    committerColumn.setLabelProvider(new HighlightingColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof PlanElement) {
                PlanElement planLine = (PlanElement) element;
                return planLine.getCommitter();
            }
            return super.getText(element);
        }
    });
    TreeViewerColumn commitDateColumn = createColumn(headings[8]);
    layout.setColumnData(commitDateColumn.getColumn(), new ColumnWeightData(80, 80));
    commitDateColumn.setLabelProvider(new HighlightingColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof PlanElement) {
                PlanElement planLine = (PlanElement) element;
                return planLine.getCommittedDate(dateFormatter);
            }
            return super.getText(element);
        }
    });
    dynamicColumns = new TreeViewerColumn[] { commitMessageColumn, authorColumn, authoredDateColumn, committerColumn, commitDateColumn };
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ElementType(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementType) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Image(org.eclipse.swt.graphics.Image) PlanElement(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.PlanElement) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ElementAction(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementAction) Tree(org.eclipse.swt.widgets.Tree) GC(org.eclipse.swt.graphics.GC)

Aggregations

ElementAction (org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementAction)2 PlanElement (org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.PlanElement)2 ElementType (org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementType)1 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GC (org.eclipse.swt.graphics.GC)1 Image (org.eclipse.swt.graphics.Image)1 Tree (org.eclipse.swt.widgets.Tree)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1