Search in sources :

Example 1 with RepositorySelectionProvider

use of org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider in project egit by eclipse.

the class RebaseInteractiveView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    GridLayoutFactory.fillDefaults().applyTo(parent);
    final FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            toolkit.dispose();
        }
    });
    form = createForm(parent, toolkit);
    createCommandToolBar(form, toolkit);
    planTreeViewer = createPlanTreeViewer(form.getBody(), toolkit);
    planLayout = new PlanLayout();
    planTreeViewer.getTree().getParent().setLayout(planLayout);
    createColumns(planLayout);
    createStepActionToolBar(toolkit);
    createPopupMenu(planTreeViewer);
    setupListeners();
    createLocalDragandDrop();
    planTreeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            PlanElement element = (PlanElement) ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (element == null)
                return;
            RepositoryCommit commit = loadCommit(element.getCommit());
            if (commit != null)
                CommitEditor.openQuiet(commit);
        }

        private RepositoryCommit loadCommit(AbbreviatedObjectId abbreviatedObjectId) {
            if (abbreviatedObjectId != null) {
                try (RevWalk walk = new RevWalk(RebaseInteractiveView.this.currentRepository)) {
                    Collection<ObjectId> resolved = walk.getObjectReader().resolve(abbreviatedObjectId);
                    if (resolved.size() == 1) {
                        RevCommit commit = walk.parseCommit(resolved.iterator().next());
                        return new RepositoryCommit(RebaseInteractiveView.this.currentRepository, commit);
                    }
                } catch (IOException e) {
                    return null;
                }
            }
            return null;
        }
    });
    prefListener = new IPreferenceChangeListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            if (!RepositoryUtil.PREFS_DIRECTORIES_REL.equals(event.getKey())) {
                return;
            }
            final Repository repo = currentRepository;
            if (repo == null)
                return;
            if (Activator.getDefault().getRepositoryUtil().contains(repo))
                return;
            // Unselect repository as it has been removed
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    currentRepository = null;
                    showRepository(null);
                }
            });
        }
    };
    InstanceScope.INSTANCE.getNode(org.eclipse.egit.core.Activator.getPluginId()).addPreferenceChangeListener(prefListener);
    uiPrefsListener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            String property = event.getProperty();
            if (UIPreferences.DATE_FORMAT.equals(property) || UIPreferences.DATE_FORMAT_CHOICE.equals(property) || UIPreferences.RESOURCEHISTORY_SHOW_RELATIVE_DATE.equals(property)) {
                refresh();
            }
        }
    };
    Activator.getDefault().getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
    IActionBars actionBars = getViewSite().getActionBars();
    IToolBarManager toolbar = actionBars.getToolBarManager();
    listenOnRepositoryViewSelection = RebaseInteractivePreferences.isReactOnSelection();
    // link with selection
    Action linkSelectionAction = new BooleanPrefAction((IPersistentPreferenceStore) Activator.getDefault().getPreferenceStore(), UIPreferences.REBASE_INTERACTIVE_SYNC_SELECTION, UIText.InteractiveRebaseView_LinkSelection) {

        @Override
        public void apply(boolean value) {
            listenOnRepositoryViewSelection = value;
        }
    };
    linkSelectionAction.setImageDescriptor(UIIcons.ELCL16_SYNCED);
    toolbar.add(linkSelectionAction);
    switchRepositoriesAction = new RepositoryToolbarAction(false, () -> currentRepository, repo -> setInput(new StructuredSelection(repo)));
    toolbar.add(switchRepositoriesAction);
    UIUtils.notifySelectionChangedWithCurrentSelection(selectionChangedListener, getSite());
    getSite().setSelectionProvider(new RepositorySelectionProvider(planTreeViewer, () -> currentRepository));
}
Also used : AdapterUtils(org.eclipse.egit.core.AdapterUtils) UIPreferences(org.eclipse.egit.ui.UIPreferences) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) DND(org.eclipse.swt.dnd.DND) CommitEditor(org.eclipse.egit.ui.internal.commit.CommitEditor) RepositoryState(org.eclipse.jgit.lib.RepositoryState) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ProcessStepsRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.ProcessStepsRebaseCommand) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) PreferenceBasedDateFormatter(org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter) KeyEvent(org.eclipse.swt.events.KeyEvent) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IEditorPart(org.eclipse.ui.IEditorPart) AbortRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.AbortRebaseCommand) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Separator(org.eclipse.jface.action.Separator) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) MenuManager(org.eclipse.jface.action.MenuManager) ToolItem(org.eclipse.swt.widgets.ToolItem) AbstractRebaseCommandHandler(org.eclipse.egit.ui.internal.commands.shared.AbstractRebaseCommandHandler) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) Transfer(org.eclipse.swt.dnd.Transfer) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) UIText(org.eclipse.egit.ui.internal.UIText) PreferenceChangeEvent(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent) SWT(org.eclipse.swt.SWT) BooleanPrefAction(org.eclipse.egit.ui.internal.actions.BooleanPrefAction) ElementType(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementType) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) ViewPart(org.eclipse.ui.part.ViewPart) RevCommit(org.eclipse.jgit.revwalk.RevCommit) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Format(org.eclipse.jgit.util.GitDateFormatter.Format) JFaceResources(org.eclipse.jface.resource.JFaceResources) RebaseInteractivePlan(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) PlanElement(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.PlanElement) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) Font(org.eclipse.swt.graphics.Font) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IViewSite(org.eclipse.ui.IViewSite) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) IActionBars(org.eclipse.ui.IActionBars) CommonUtils(org.eclipse.egit.ui.internal.CommonUtils) Form(org.eclipse.ui.forms.widgets.Form) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) ToolTip(org.eclipse.jface.window.ToolTip) Repository(org.eclipse.jgit.lib.Repository) ElementAction(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementAction) DisposeEvent(org.eclipse.swt.events.DisposeEvent) DisposeListener(org.eclipse.swt.events.DisposeListener) IAction(org.eclipse.jface.action.IAction) ToolBar(org.eclipse.swt.widgets.ToolBar) IToolBarManager(org.eclipse.jface.action.IToolBarManager) SWTKeySupport(org.eclipse.jface.bindings.keys.SWTKeySupport) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) GC(org.eclipse.swt.graphics.GC) ISelectionListener(org.eclipse.ui.ISelectionListener) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Collection(java.util.Collection) GitDateFormatter(org.eclipse.jgit.util.GitDateFormatter) Display(org.eclipse.swt.widgets.Display) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) AbbreviatedObjectId(org.eclipse.jgit.lib.AbbreviatedObjectId) List(java.util.List) Tree(org.eclipse.swt.widgets.Tree) ISelection(org.eclipse.jface.viewers.ISelection) TreeViewer(org.eclipse.jface.viewers.TreeViewer) UIIcons(org.eclipse.egit.ui.internal.UIIcons) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ISelectionService(org.eclipse.ui.ISelectionService) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) Activator(org.eclipse.egit.ui.Activator) Image(org.eclipse.swt.graphics.Image) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ContinueRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.ContinueRebaseCommand) IWorkbenchActionConstants(org.eclipse.ui.IWorkbenchActionConstants) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Action(org.eclipse.jface.action.Action) TreeItem(org.eclipse.swt.widgets.TreeItem) ObjectId(org.eclipse.jgit.lib.ObjectId) IResource(org.eclipse.core.resources.IResource) UIUtils(org.eclipse.egit.ui.UIUtils) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) RepositoriesView(org.eclipse.egit.ui.internal.repository.RepositoriesView) Control(org.eclipse.swt.widgets.Control) SkipRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.SkipRebaseCommand) DisposeListener(org.eclipse.swt.events.DisposeListener) BooleanPrefAction(org.eclipse.egit.ui.internal.actions.BooleanPrefAction) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) ElementAction(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementAction) IAction(org.eclipse.jface.action.IAction) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) Action(org.eclipse.jface.action.Action) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) PlanElement(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.PlanElement) AbbreviatedObjectId(org.eclipse.jgit.lib.AbbreviatedObjectId) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) IActionBars(org.eclipse.ui.IActionBars) RevCommit(org.eclipse.jgit.revwalk.RevCommit) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) PreferenceChangeEvent(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) Repository(org.eclipse.jgit.lib.Repository) IToolBarManager(org.eclipse.jface.action.IToolBarManager) Collection(java.util.Collection) BooleanPrefAction(org.eclipse.egit.ui.internal.actions.BooleanPrefAction)

Example 2 with RepositorySelectionProvider

use of org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider in project egit by eclipse.

the class StagingView method createPartControl.

@Override
public void createPartControl(final Composite parent) {
    GridLayoutFactory.fillDefaults().applyTo(parent);
    toolkit = new FormToolkit(parent.getDisplay());
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (commitMessageComponent.isAmending() || userEnteredCommitMessage())
                saveCommitMessageComponentState();
            else
                deleteCommitMessageComponentState();
            resources.dispose();
            toolkit.dispose();
        }
    });
    form = toolkit.createForm(parent);
    parent.addControlListener(new ControlListener() {

        private int[] defaultWeights = { 1, 1 };

        @Override
        public void controlResized(ControlEvent e) {
            org.eclipse.swt.graphics.Rectangle b = parent.getBounds();
            int oldOrientation = mainSashForm.getOrientation();
            if ((oldOrientation == SWT.HORIZONTAL) && (b.height > b.width)) {
                mainSashForm.setOrientation(SWT.VERTICAL);
                mainSashForm.setWeights(defaultWeights);
            } else if ((oldOrientation == SWT.VERTICAL) && (b.height <= b.width)) {
                mainSashForm.setOrientation(SWT.HORIZONTAL);
                mainSashForm.setWeights(defaultWeights);
            }
        }

        @Override
        public void controlMoved(ControlEvent e) {
        // ignore
        }
    });
    form.setImage(getImage(UIIcons.REPOSITORY));
    form.setText(UIText.StagingView_NoSelectionTitle);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(form);
    toolkit.decorateFormHeading(form);
    GridLayoutFactory.swtDefaults().applyTo(form.getBody());
    mainSashForm = new SashForm(form.getBody(), SWT.HORIZONTAL);
    saveSashFormWeightsOnDisposal(mainSashForm, HORIZONTAL_SASH_FORM_WEIGHT);
    toolkit.adapt(mainSashForm, true, true);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(mainSashForm);
    stagingSashForm = new SashForm(mainSashForm, getStagingFormOrientation());
    saveSashFormWeightsOnDisposal(stagingSashForm, STAGING_SASH_FORM_WEIGHT);
    toolkit.adapt(stagingSashForm, true, true);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(stagingSashForm);
    unstageAction = new Action(UIText.StagingView_UnstageItemMenuLabel, UIIcons.UNSTAGE) {

        @Override
        public void run() {
            unstage((IStructuredSelection) stagedViewer.getSelection());
        }
    };
    unstageAction.setToolTipText(UIText.StagingView_UnstageItemTooltip);
    stageAction = new Action(UIText.StagingView_StageItemMenuLabel, UIIcons.ELCL16_ADD) {

        @Override
        public void run() {
            stage((IStructuredSelection) unstagedViewer.getSelection());
        }
    };
    stageAction.setToolTipText(UIText.StagingView_StageItemTooltip);
    unstageAction.setEnabled(false);
    stageAction.setEnabled(false);
    unstageAllAction = new Action(UIText.StagingView_UnstageAllItemMenuLabel, UIIcons.UNSTAGE_ALL) {

        @Override
        public void run() {
            stagedViewer.getTree().selectAll();
            unstage((IStructuredSelection) stagedViewer.getSelection());
        }
    };
    unstageAllAction.setToolTipText(UIText.StagingView_UnstageAllItemTooltip);
    stageAllAction = new Action(UIText.StagingView_StageAllItemMenuLabel, UIIcons.ELCL16_ADD_ALL) {

        @Override
        public void run() {
            unstagedViewer.getTree().selectAll();
            stage((IStructuredSelection) unstagedViewer.getSelection());
        }
    };
    stageAllAction.setToolTipText(UIText.StagingView_StageAllItemTooltip);
    unstageAllAction.setEnabled(false);
    stageAllAction.setEnabled(false);
    unstagedSection = toolkit.createSection(stagingSashForm, ExpandableComposite.SHORT_TITLE_BAR);
    unstagedSection.clientVerticalSpacing = 0;
    unstagedSection.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    createUnstagedToolBarComposite();
    Composite unstagedComposite = toolkit.createComposite(unstagedSection);
    toolkit.paintBordersFor(unstagedComposite);
    unstagedSection.setClient(unstagedComposite);
    GridLayoutFactory.fillDefaults().applyTo(unstagedComposite);
    unstagedViewer = createViewer(unstagedComposite, true, selection -> unstage(selection), stageAction);
    unstagedViewer.addSelectionChangedListener(event -> {
        boolean hasSelection = !event.getSelection().isEmpty();
        if (hasSelection != stageAction.isEnabled()) {
            stageAction.setEnabled(hasSelection);
            unstagedToolBarManager.update(true);
        }
    });
    Composite rebaseAndCommitComposite = toolkit.createComposite(mainSashForm);
    rebaseAndCommitComposite.setLayout(GridLayoutFactory.fillDefaults().create());
    rebaseSection = toolkit.createSection(rebaseAndCommitComposite, ExpandableComposite.SHORT_TITLE_BAR);
    rebaseSection.clientVerticalSpacing = 0;
    rebaseSection.setText(UIText.StagingView_RebaseLabel);
    Composite rebaseComposite = toolkit.createComposite(rebaseSection);
    toolkit.paintBordersFor(rebaseComposite);
    rebaseSection.setClient(rebaseComposite);
    rebaseSection.setLayoutData(GridDataFactory.fillDefaults().create());
    rebaseComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(true).create());
    GridDataFactory buttonGridData = GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER);
    this.rebaseAbortButton = toolkit.createButton(rebaseComposite, UIText.StagingView_RebaseAbort, SWT.PUSH);
    rebaseAbortButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            rebaseAbort();
        }
    });
    rebaseAbortButton.setImage(getImage(UIIcons.REBASE_ABORT));
    buttonGridData.applyTo(rebaseAbortButton);
    this.rebaseSkipButton = toolkit.createButton(rebaseComposite, UIText.StagingView_RebaseSkip, SWT.PUSH);
    rebaseSkipButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            rebaseSkip();
        }
    });
    rebaseSkipButton.setImage(getImage(UIIcons.REBASE_SKIP));
    buttonGridData.applyTo(rebaseSkipButton);
    this.rebaseContinueButton = toolkit.createButton(rebaseComposite, UIText.StagingView_RebaseContinue, SWT.PUSH);
    rebaseContinueButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            rebaseContinue();
        }
    });
    rebaseContinueButton.setImage(getImage(UIIcons.REBASE_CONTINUE));
    buttonGridData.applyTo(rebaseContinueButton);
    showControl(rebaseSection, false);
    commitMessageSection = toolkit.createSection(rebaseAndCommitComposite, ExpandableComposite.SHORT_TITLE_BAR);
    commitMessageSection.clientVerticalSpacing = 0;
    commitMessageSection.setText(UIText.StagingView_CommitMessage);
    commitMessageSection.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    Composite commitMessageToolbarComposite = toolkit.createComposite(commitMessageSection);
    commitMessageToolbarComposite.setBackground(null);
    commitMessageToolbarComposite.setLayout(createRowLayoutWithoutMargin());
    commitMessageSection.setTextClient(commitMessageToolbarComposite);
    ToolBarManager commitMessageToolBarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
    amendPreviousCommitAction = new Action(UIText.StagingView_Ammend_Previous_Commit, IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            commitMessageComponent.setAmendingButtonSelection(isChecked());
            updateMessage();
        }
    };
    amendPreviousCommitAction.setImageDescriptor(UIIcons.AMEND_COMMIT);
    commitMessageToolBarManager.add(amendPreviousCommitAction);
    signedOffByAction = new Action(UIText.StagingView_Add_Signed_Off_By, IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            commitMessageComponent.setSignedOffButtonSelection(isChecked());
        }
    };
    signedOffByAction.setImageDescriptor(UIIcons.SIGNED_OFF);
    commitMessageToolBarManager.add(signedOffByAction);
    addChangeIdAction = new Action(UIText.StagingView_Add_Change_ID, IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            commitMessageComponent.setChangeIdButtonSelection(isChecked());
        }
    };
    addChangeIdAction.setImageDescriptor(UIIcons.GERRIT);
    commitMessageToolBarManager.add(addChangeIdAction);
    commitMessageToolBarManager.createControl(commitMessageToolbarComposite);
    Composite commitMessageComposite = toolkit.createComposite(commitMessageSection);
    commitMessageSection.setClient(commitMessageComposite);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(commitMessageComposite);
    warningLabel = new ToggleableWarningLabel(commitMessageComposite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).exclude(true).applyTo(warningLabel);
    Composite commitMessageTextComposite = toolkit.createComposite(commitMessageComposite);
    toolkit.paintBordersFor(commitMessageTextComposite);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(commitMessageTextComposite);
    GridLayoutFactory.fillDefaults().numColumns(1).extendedMargins(2, 2, 2, 2).applyTo(commitMessageTextComposite);
    final CommitProposalProcessor commitProposalProcessor = new CommitProposalProcessor() {

        @Override
        protected Collection<String> computeFileNameProposals() {
            return getStagedFileNames();
        }

        @Override
        protected Collection<String> computeMessageProposals() {
            return CommitMessageHistory.getCommitHistory();
        }
    };
    commitMessageText = new CommitMessageArea(commitMessageTextComposite, EMPTY_STRING, SWT.NONE) {

        @Override
        protected CommitProposalProcessor getCommitProposalProcessor() {
            return commitProposalProcessor;
        }

        @Override
        protected IHandlerService getHandlerService() {
            return CommonUtils.getService(getSite(), IHandlerService.class);
        }
    };
    commitMessageText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(commitMessageText);
    UIUtils.addBulbDecorator(commitMessageText.getTextWidget(), UIText.CommitDialog_ContentAssist);
    Composite composite = toolkit.createComposite(commitMessageComposite);
    toolkit.paintBordersFor(composite);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(composite);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(composite);
    toolkit.createLabel(composite, UIText.StagingView_Author).setForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
    authorText = toolkit.createText(composite, null);
    authorText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    authorText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    toolkit.createLabel(composite, UIText.StagingView_Committer).setForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
    committerText = toolkit.createText(composite, null);
    committerText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
    committerText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    Composite buttonsContainer = toolkit.createComposite(composite);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 1).indent(0, 8).applyTo(buttonsContainer);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(buttonsContainer);
    ignoreErrors = toolkit.createButton(buttonsContainer, UIText.StagingView_IgnoreErrors, SWT.CHECK);
    ignoreErrors.setSelection(false);
    ignoreErrors.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateMessage();
            updateCommitButtons();
        }
    });
    getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (isDisposed()) {
                getPreferenceStore().removePropertyChangeListener(this);
                return;
            }
            asyncExec(() -> {
                updateIgnoreErrorsButtonVisibility();
                updateMessage();
                updateCommitButtons();
            });
        }
    });
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING).grab(true, true).applyTo(ignoreErrors);
    updateIgnoreErrorsButtonVisibility();
    // $NON-NLS-1$
    Label filler = toolkit.createLabel(buttonsContainer, "");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(filler);
    Composite commitButtonsContainer = toolkit.createComposite(buttonsContainer);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(commitButtonsContainer);
    GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true).applyTo(commitButtonsContainer);
    this.commitAndPushButton = toolkit.createButton(commitButtonsContainer, UIText.StagingView_CommitAndPush, SWT.PUSH);
    commitAndPushButton.setImage(getImage(UIIcons.PUSH));
    commitAndPushButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            commit(true);
        }
    });
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(commitAndPushButton);
    this.commitButton = toolkit.createButton(commitButtonsContainer, UIText.StagingView_Commit, SWT.PUSH);
    commitButton.setImage(getImage(UIIcons.COMMIT));
    commitButton.setText(UIText.StagingView_Commit);
    commitButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            commit(false);
        }
    });
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(commitButton);
    stagedSection = toolkit.createSection(stagingSashForm, ExpandableComposite.SHORT_TITLE_BAR);
    stagedSection.clientVerticalSpacing = 0;
    createStagedToolBarComposite();
    Composite stagedComposite = toolkit.createComposite(stagedSection);
    toolkit.paintBordersFor(stagedComposite);
    stagedSection.setClient(stagedComposite);
    GridLayoutFactory.fillDefaults().applyTo(stagedComposite);
    stagedViewer = createViewer(stagedComposite, false, selection -> stage(selection), unstageAction);
    stagedViewer.getLabelProvider().addListener(event -> {
        updateMessage();
        updateCommitButtons();
    });
    stagedViewer.addSelectionChangedListener(event -> {
        boolean hasSelection = !event.getSelection().isEmpty();
        if (hasSelection != unstageAction.isEnabled()) {
            unstageAction.setEnabled(hasSelection);
            stagedToolBarManager.update(true);
        }
    });
    selectionChangedListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (part == getSite().getPart()) {
                return;
            }
            // don't accept text selection, only structural one
            if (selection instanceof StructuredSelection) {
                reactOnSelection((StructuredSelection) selection);
            }
        }
    };
    partListener = new PartListener();
    IPreferenceStore preferenceStore = getPreferenceStore();
    if (preferenceStore.contains(UIPreferences.STAGING_VIEW_SYNC_SELECTION))
        reactOnSelection = preferenceStore.getBoolean(UIPreferences.STAGING_VIEW_SYNC_SELECTION);
    else
        preferenceStore.setDefault(UIPreferences.STAGING_VIEW_SYNC_SELECTION, true);
    preferenceStore.addPropertyChangeListener(uiPrefsListener);
    InstanceScope.INSTANCE.getNode(org.eclipse.egit.core.Activator.getPluginId()).addPreferenceChangeListener(prefListener);
    updateSectionText();
    stagedSection.setToolTipText(UIText.StagingView_StagedChangesTooltip);
    unstagedSection.setToolTipText(UIText.StagingView_UnstagedChangesTooltip);
    updateToolbar();
    enableCommitWidgets(false);
    refreshAction.setEnabled(false);
    createPopupMenu(unstagedViewer);
    createPopupMenu(stagedViewer);
    final ICommitMessageComponentNotifications listener = new ICommitMessageComponentNotifications() {

        @Override
        public void updateSignedOffToggleSelection(boolean selection) {
            signedOffByAction.setChecked(selection);
        }

        @Override
        public void updateChangeIdToggleSelection(boolean selection) {
            addChangeIdAction.setChecked(selection);
            commitAndPushButton.setImage(getImage(selection ? UIIcons.GERRIT : UIIcons.PUSH));
        }

        @Override
        public void statusUpdated() {
            updateMessage();
        }
    };
    commitMessageComponent = new CommitMessageComponent(listener);
    commitMessageComponent.attachControls(commitMessageText, authorText, committerText);
    // allow to commit with ctrl-enter
    commitMessageText.getTextWidget().addVerifyKeyListener(new VerifyKeyListener() {

        @Override
        public void verifyKey(VerifyEvent event) {
            if (UIUtils.isSubmitKeyEvent(event)) {
                event.doit = false;
                commit(false);
            }
        }
    });
    commitMessageText.getTextWidget().addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            // Ctrl+Enter shortcut only works when the focus is on the commit message text
            String commitButtonTooltip = MessageFormat.format(UIText.StagingView_CommitToolTip, UIUtils.SUBMIT_KEY_STROKE.format());
            commitButton.setToolTipText(commitButtonTooltip);
        }

        @Override
        public void focusLost(FocusEvent e) {
            commitButton.setToolTipText(null);
        }
    });
    // react on selection changes
    IWorkbenchPartSite site = getSite();
    ISelectionService srv = CommonUtils.getService(site, ISelectionService.class);
    srv.addPostSelectionListener(selectionChangedListener);
    CommonUtils.getService(site, IPartService.class).addPartListener(partListener);
    // Use current selection to populate staging view
    UIUtils.notifySelectionChangedWithCurrentSelection(selectionChangedListener, site);
    site.setSelectionProvider(new RepositorySelectionProvider(new MultiViewerSelectionProvider(unstagedViewer, stagedViewer), () -> realRepository));
    ViewerFilter filter = new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            StagingViewContentProvider contentProvider = getContentProvider((TreeViewer) viewer);
            if (element instanceof StagingEntry)
                return contentProvider.isInFilter((StagingEntry) element);
            else if (element instanceof StagingFolderEntry)
                return contentProvider.hasVisibleChildren((StagingFolderEntry) element);
            return true;
        }
    };
    unstagedViewer.addFilter(filter);
    stagedViewer.addFilter(filter);
    restoreSashFormWeights();
    reactOnInitialSelection();
    IWorkbenchSiteProgressService service = CommonUtils.getService(getSite(), IWorkbenchSiteProgressService.class);
    if (service != null && reactOnSelection)
        // If we are linked, each time IndexDiffUpdateJob starts, indicate
        // that the view is busy (e.g. reload() will trigger this job in
        // background!).
        service.showBusyForFamily(org.eclipse.egit.core.JobFamilies.INDEX_DIFF_CACHE_UPDATE);
}
Also used : SashForm(org.eclipse.swt.custom.SashForm) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) RepositoryState(org.eclipse.jgit.lib.RepositoryState) DiffViewer(org.eclipse.egit.ui.internal.commit.DiffViewer) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Cursor(org.eclipse.swt.graphics.Cursor) IEditorPart(org.eclipse.ui.IEditorPart) EnumSet(java.util.EnumSet) Nullable(org.eclipse.jgit.annotations.Nullable) AbortRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.AbortRebaseCommand) JobFamilies(org.eclipse.egit.ui.JobFamilies) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) Constants(org.eclipse.jgit.lib.Constants) Transfer(org.eclipse.swt.dnd.Transfer) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Window(org.eclipse.jface.window.Window) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) Path(org.eclipse.core.runtime.Path) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ControlListener(org.eclipse.swt.events.ControlListener) IFileEditorInput(org.eclipse.ui.IFileEditorInput) LinkedHashMap(java.util.LinkedHashMap) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) LaunchFinder(org.eclipse.egit.ui.internal.branch.LaunchFinder) CommitMessageArea(org.eclipse.egit.ui.internal.dialogs.CommitMessageArea) TextTransfer(org.eclipse.swt.dnd.TextTransfer) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) ILabelDecorator(org.eclipse.jface.viewers.ILabelDecorator) Section(org.eclipse.ui.forms.widgets.Section) ControlContribution(org.eclipse.jface.action.ControlContribution) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) IMemento(org.eclipse.ui.IMemento) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) IActionBars(org.eclipse.ui.IActionBars) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Form(org.eclipse.ui.forms.widgets.Form) ICommitMessageComponentNotifications(org.eclipse.egit.ui.internal.dialogs.ICommitMessageComponentNotifications) NoFilepatternException(org.eclipse.jgit.api.errors.NoFilepatternException) UntrackOperation(org.eclipse.egit.core.op.UntrackOperation) ModifyListener(org.eclipse.swt.events.ModifyListener) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IProblemDecoratable(org.eclipse.egit.ui.internal.decorators.IProblemDecoratable) PushMode(org.eclipse.egit.ui.internal.push.PushMode) DisposeListener(org.eclipse.swt.events.DisposeListener) MultiViewerSelectionProvider(org.eclipse.egit.ui.internal.selection.MultiViewerSelectionProvider) IAction(org.eclipse.jface.action.IAction) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) AddCommand(org.eclipse.jgit.api.AddCommand) RuleUtil(org.eclipse.egit.core.internal.job.RuleUtil) IStatus(org.eclipse.core.runtime.IStatus) ISelectionListener(org.eclipse.ui.ISelectionListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) IPartListener2(org.eclipse.ui.IPartListener2) UndoRedoActionGroup(org.eclipse.ui.operations.UndoRedoActionGroup) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) ActionUtils(org.eclipse.egit.ui.internal.ActionUtils) Collection(java.util.Collection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AssumeUnchangedOperation(org.eclipse.egit.core.op.AssumeUnchangedOperation) CommitProposalProcessor(org.eclipse.egit.ui.internal.commit.CommitProposalProcessor) GitLabels(org.eclipse.egit.ui.internal.GitLabels) ISelection(org.eclipse.jface.viewers.ISelection) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IShowInTarget(org.eclipse.ui.part.IShowInTarget) UIIcons(org.eclipse.egit.ui.internal.UIIcons) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) OpenEvent(org.eclipse.jface.viewers.OpenEvent) ToggleableWarningLabel(org.eclipse.egit.ui.internal.components.ToggleableWarningLabel) Activator(org.eclipse.egit.ui.Activator) Image(org.eclipse.swt.graphics.Image) MessageFormat(java.text.MessageFormat) CommitOperation(org.eclipse.egit.core.op.CommitOperation) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore) HashSet(java.util.HashSet) ContinueRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.ContinueRebaseCommand) IMarker(org.eclipse.core.resources.IMarker) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ContentViewer(org.eclipse.jface.viewers.ContentViewer) Action(org.eclipse.jface.action.Action) IgnoreOperationUI(org.eclipse.egit.ui.internal.operations.IgnoreOperationUI) CheckoutCommand(org.eclipse.jgit.api.CheckoutCommand) Consumer(java.util.function.Consumer) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) ToolBarManager(org.eclipse.jface.action.ToolBarManager) IContributionItem(org.eclipse.jface.action.IContributionItem) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Comparator(java.util.Comparator) SkipRebaseCommand(org.eclipse.egit.ui.internal.commands.shared.SkipRebaseCommand) AdapterUtils(org.eclipse.egit.core.AdapterUtils) UIPreferences(org.eclipse.egit.ui.UIPreferences) DialogSettings(org.eclipse.jface.dialogs.DialogSettings) DND(org.eclipse.swt.dnd.DND) CoreException(org.eclipse.core.runtime.CoreException) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) FocusEvent(org.eclipse.swt.events.FocusEvent) ReplaceWithOursTheirsMenu(org.eclipse.egit.ui.internal.actions.ReplaceWithOursTheirsMenu) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) ResetCommand(org.eclipse.jgit.api.ResetCommand) Matcher(java.util.regex.Matcher) CommitHelper(org.eclipse.egit.ui.internal.commit.CommitHelper) PartInitException(org.eclipse.ui.PartInitException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Separator(org.eclipse.jface.action.Separator) Text(org.eclipse.swt.widgets.Text) MenuManager(org.eclipse.jface.action.MenuManager) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) DeletePathsOperationUI(org.eclipse.egit.ui.internal.operations.DeletePathsOperationUI) AbstractRebaseCommandHandler(org.eclipse.egit.ui.internal.commands.shared.AbstractRebaseCommandHandler) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) ListenerHandle(org.eclipse.jgit.events.ListenerHandle) CommitMessageComponentState(org.eclipse.egit.ui.internal.dialogs.CommitMessageComponentState) UIText(org.eclipse.egit.ui.internal.UIText) PreferenceChangeEvent(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent) JobUtil(org.eclipse.egit.core.internal.job.JobUtil) ActionCommands(org.eclipse.egit.ui.internal.actions.ActionCommands) SWT(org.eclipse.swt.SWT) BooleanPrefAction(org.eclipse.egit.ui.internal.actions.BooleanPrefAction) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) ViewPart(org.eclipse.ui.part.ViewPart) JFaceResources(org.eclipse.jface.resource.JFaceResources) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) ControlEvent(org.eclipse.swt.events.ControlEvent) IContainer(org.eclipse.core.resources.IContainer) CommitMessageHistory(org.eclipse.egit.ui.internal.commit.CommitMessageHistory) IShowInSource(org.eclipse.ui.part.IShowInSource) ShowInContext(org.eclipse.ui.part.ShowInContext) IFile(org.eclipse.core.resources.IFile) GridData(org.eclipse.swt.layout.GridData) LinkedHashSet(java.util.LinkedHashSet) BaseLabelProvider(org.eclipse.jface.viewers.BaseLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IViewSite(org.eclipse.ui.IViewSite) ExecutionException(org.eclipse.core.commands.ExecutionException) CommonUtils(org.eclipse.egit.ui.internal.CommonUtils) File(java.io.File) IURIEditorInput(org.eclipse.ui.IURIEditorInput) IMenuManager(org.eclipse.jface.action.IMenuManager) ActionFactory(org.eclipse.ui.actions.ActionFactory) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) IPartService(org.eclipse.ui.IPartService) Repository(org.eclipse.jgit.lib.Repository) GridLayout(org.eclipse.swt.layout.GridLayout) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) IndexDiffChangedListener(org.eclipse.egit.core.internal.indexdiff.IndexDiffChangedListener) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) IPath(org.eclipse.core.runtime.IPath) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) CommitMessageComponentStateManager(org.eclipse.egit.ui.internal.dialogs.CommitMessageComponentStateManager) Display(org.eclipse.swt.widgets.Display) IUndoContext(org.eclipse.core.commands.operations.IUndoContext) IHandlerService(org.eclipse.ui.handlers.IHandlerService) List(java.util.List) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) Tree(org.eclipse.swt.widgets.Tree) IFormColors(org.eclipse.ui.forms.IFormColors) CommitJob(org.eclipse.egit.ui.internal.commit.CommitJob) Pattern(java.util.regex.Pattern) IMenuListener(org.eclipse.jface.action.IMenuListener) RmCommand(org.eclipse.jgit.api.RmCommand) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ISelectionService(org.eclipse.ui.ISelectionService) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) CommonUtils.runCommand(org.eclipse.egit.ui.internal.CommonUtils.runCommand) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) FocusListener(org.eclipse.swt.events.FocusListener) VerifyEvent(org.eclipse.swt.events.VerifyEvent) FileTransfer(org.eclipse.swt.dnd.FileTransfer) SpellcheckableMessageArea(org.eclipse.egit.ui.internal.dialogs.SpellcheckableMessageArea) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) Job(org.eclipse.core.runtime.jobs.Job) ProblemLabelDecorator(org.eclipse.egit.ui.internal.decorators.ProblemLabelDecorator) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) DecoratingLabelProvider(org.eclipse.jface.viewers.DecoratingLabelProvider) TreeItem(org.eclipse.swt.widgets.TreeItem) ObjectId(org.eclipse.jgit.lib.ObjectId) RowLayout(org.eclipse.swt.layout.RowLayout) CommitMessageComponent(org.eclipse.egit.ui.internal.dialogs.CommitMessageComponent) IResource(org.eclipse.core.resources.IResource) GerritUtil(org.eclipse.egit.core.internal.gerrit.GerritUtil) UIUtils(org.eclipse.egit.ui.UIUtils) NonNull(org.eclipse.jgit.annotations.NonNull) Git(org.eclipse.jgit.api.Git) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) Label(org.eclipse.swt.widgets.Label) ToggleableWarningLabel(org.eclipse.egit.ui.internal.components.ToggleableWarningLabel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) CommitProposalProcessor(org.eclipse.egit.ui.internal.commit.CommitProposalProcessor) DiffViewer(org.eclipse.egit.ui.internal.commit.DiffViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ContentViewer(org.eclipse.jface.viewers.ContentViewer) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) ISelectionListener(org.eclipse.ui.ISelectionListener) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlListener(org.eclipse.swt.events.ControlListener) ISelectionService(org.eclipse.ui.ISelectionService) MultiViewerSelectionProvider(org.eclipse.egit.ui.internal.selection.MultiViewerSelectionProvider) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ToggleableWarningLabel(org.eclipse.egit.ui.internal.components.ToggleableWarningLabel) ICommitMessageComponentNotifications(org.eclipse.egit.ui.internal.dialogs.ICommitMessageComponentNotifications) IHandlerService(org.eclipse.ui.handlers.IHandlerService) FocusListener(org.eclipse.swt.events.FocusListener) DisposeListener(org.eclipse.swt.events.DisposeListener) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) BooleanPrefAction(org.eclipse.egit.ui.internal.actions.BooleanPrefAction) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IPartService(org.eclipse.ui.IPartService) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ToolBarManager(org.eclipse.jface.action.ToolBarManager) ISelection(org.eclipse.jface.viewers.ISelection) VerifyEvent(org.eclipse.swt.events.VerifyEvent) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SashForm(org.eclipse.swt.custom.SashForm) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) ControlEvent(org.eclipse.swt.events.ControlEvent) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CommitMessageComponent(org.eclipse.egit.ui.internal.dialogs.CommitMessageComponent) CommitMessageArea(org.eclipse.egit.ui.internal.dialogs.CommitMessageArea)

Example 3 with RepositorySelectionProvider

use of org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider in project egit by eclipse.

the class GitHistoryPage method createControl.

@Override
public void createControl(final Composite parent) {
    trace = GitTraceLocation.HISTORYVIEW.isActive();
    if (trace)
        GitTraceLocation.getTrace().traceEntry(GitTraceLocation.HISTORYVIEW.getLocation());
    attachSelectionTracker();
    historyControl = createMainPanel(parent);
    warningComposite = new Composite(historyControl, SWT.NONE);
    warningComposite.setLayout(new GridLayout(2, false));
    warningComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    warningLabel = new CLabel(warningComposite, SWT.NONE);
    warningLabel.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    warningLabel.setToolTipText(UIText.GitHistoryPage_IncompleteListTooltip);
    Link preferencesLink = new Link(warningComposite, SWT.NONE);
    preferencesLink.setText(UIText.GitHistoryPage_PreferencesLink);
    preferencesLink.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // $NON-NLS-1$
            String preferencePageId = "org.eclipse.egit.ui.internal.preferences.HistoryPreferencePage";
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getSite().getShell(), preferencePageId, new String[] { preferencePageId }, null);
            dialog.open();
        }
    });
    GridDataFactory.fillDefaults().grab(true, true).applyTo(historyControl);
    graphDetailSplit = new SashForm(historyControl, SWT.VERTICAL);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(graphDetailSplit);
    graph = new CommitGraphTable(graphDetailSplit, getSite(), popupMgr, this, resources);
    Activator.getDefault().getPreferenceStore().addPropertyChangeListener(listener);
    revInfoSplit = new SashForm(graphDetailSplit, SWT.HORIZONTAL);
    commentAndDiffScrolledComposite = new ScrolledComposite(revInfoSplit, SWT.H_SCROLL | SWT.V_SCROLL);
    commentAndDiffScrolledComposite.setExpandHorizontal(true);
    commentAndDiffScrolledComposite.setExpandVertical(true);
    commentAndDiffComposite = new Composite(commentAndDiffScrolledComposite, SWT.NONE);
    commentAndDiffScrolledComposite.setContent(commentAndDiffComposite);
    commentAndDiffComposite.setLayout(GridLayoutFactory.fillDefaults().create());
    commentViewer = new CommitMessageViewer(commentAndDiffComposite, getPartSite());
    commentViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    commentViewer.addTextListener(new ITextListener() {

        @Override
        public void textChanged(TextEvent event) {
            resizeCommentAndDiffScrolledComposite();
        }
    });
    commentAndDiffComposite.setBackground(commentViewer.getControl().getBackground());
    HyperlinkSourceViewer.Configuration configuration = new HyperlinkSourceViewer.Configuration(EditorsUI.getPreferenceStore()) {

        @Override
        public int getHyperlinkStateMask(ISourceViewer sourceViewer) {
            return SWT.NONE;
        }

        @Override
        protected IHyperlinkDetector[] internalGetHyperlinkDetectors(ISourceViewer sourceViewer) {
            IHyperlinkDetector[] registered = super.internalGetHyperlinkDetectors(sourceViewer);
            // want those to show always.
            if (registered == null) {
                return new IHyperlinkDetector[] { new CommitMessageViewer.KnownHyperlinksDetector() };
            } else {
                IHyperlinkDetector[] result = new IHyperlinkDetector[registered.length + 1];
                System.arraycopy(registered, 0, result, 0, registered.length);
                result[registered.length] = new CommitMessageViewer.KnownHyperlinksDetector();
                return result;
            }
        }

        @Override
        public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
            return new String[] { IDocument.DEFAULT_CONTENT_TYPE, CommitMessageViewer.HEADER_CONTENT_TYPE, CommitMessageViewer.FOOTER_CONTENT_TYPE };
        }

        @Override
        public IPresentationReconciler getPresentationReconciler(ISourceViewer viewer) {
            PresentationReconciler reconciler = new PresentationReconciler();
            reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(viewer));
            DefaultDamagerRepairer hyperlinkDamagerRepairer = new DefaultDamagerRepairer(new HyperlinkTokenScanner(this, viewer));
            reconciler.setDamager(hyperlinkDamagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
            reconciler.setRepairer(hyperlinkDamagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
            TextAttribute headerDefault = new TextAttribute(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
            DefaultDamagerRepairer headerDamagerRepairer = new DefaultDamagerRepairer(new HyperlinkTokenScanner(this, viewer, headerDefault));
            reconciler.setDamager(headerDamagerRepairer, CommitMessageViewer.HEADER_CONTENT_TYPE);
            reconciler.setRepairer(headerDamagerRepairer, CommitMessageViewer.HEADER_CONTENT_TYPE);
            DefaultDamagerRepairer footerDamagerRepairer = new DefaultDamagerRepairer(new FooterTokenScanner(this, viewer));
            reconciler.setDamager(footerDamagerRepairer, CommitMessageViewer.FOOTER_CONTENT_TYPE);
            reconciler.setRepairer(footerDamagerRepairer, CommitMessageViewer.FOOTER_CONTENT_TYPE);
            return reconciler;
        }
    };
    commentViewer.configure(configuration);
    diffViewer = new DiffViewer(commentAndDiffComposite, null, SWT.NONE);
    diffViewer.configure(new DiffViewer.Configuration(EditorsUI.getPreferenceStore()));
    diffViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    setWrap(store.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_WRAP));
    commentAndDiffScrolledComposite.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            if (!resizing && commentViewer.getTextWidget().getWordWrap()) {
                resizeCommentAndDiffScrolledComposite();
            }
        }
    });
    fileViewer = new CommitFileDiffViewer(revInfoSplit, getSite());
    fileViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            List<FileDiff> diffs = new ArrayList<>();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection sel = (IStructuredSelection) selection;
                for (Object obj : sel.toList()) if (obj instanceof FileDiff)
                    diffs.add((FileDiff) obj);
            }
            formatDiffs(diffs);
        }
    });
    layoutSashForm(graphDetailSplit, UIPreferences.RESOURCEHISTORY_GRAPH_SPLIT);
    layoutSashForm(revInfoSplit, UIPreferences.RESOURCEHISTORY_REV_SPLIT);
    attachCommitSelectionChanged();
    initActions();
    getSite().setSelectionProvider(new RepositorySelectionProvider(graph.getTableView(), () -> {
        HistoryPageInput myInput = getInputInternal();
        return myInput != null ? myInput.getRepository() : null;
    }));
    getSite().registerContextMenu(POPUP_ID, popupMgr, graph.getTableView());
    // Track which of our controls has the focus, so that we can focus the
    // last focused one in setFocus().
    focusTracker = new FocusTracker();
    trackFocus(graph.getControl());
    trackFocus(diffViewer.getControl());
    trackFocus(commentViewer.getControl());
    trackFocus(fileViewer.getControl());
    layout();
    myRefsChangedHandle = Repository.getGlobalListenerList().addRefsChangedListener(this);
    IToolBarManager manager = getSite().getActionBars().getToolBarManager();
    searchBar = new // $NON-NLS-1$
    SearchBar(// $NON-NLS-1$
    GitHistoryPage.class.getName() + ".searchBar", graph, actions.findAction, getSite().getActionBars());
    // $NON-NLS-1$
    manager.prependToGroup("org.eclipse.team.ui.historyView", searchBar);
    getSite().getActionBars().updateActionBars();
    if (trace)
        GitTraceLocation.getTrace().traceExit(GitTraceLocation.HISTORYVIEW.getLocation());
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) ITextListener(org.eclipse.jface.text.ITextListener) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TextAttribute(org.eclipse.jface.text.TextAttribute) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) DefaultDamagerRepairer(org.eclipse.jface.text.rules.DefaultDamagerRepairer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FocusTracker(org.eclipse.egit.ui.internal.commit.FocusTracker) HyperlinkTokenScanner(org.eclipse.egit.ui.internal.dialogs.HyperlinkTokenScanner) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IShowInTargetList(org.eclipse.ui.part.IShowInTargetList) ArrayList(java.util.ArrayList) List(java.util.List) PresentationReconciler(org.eclipse.jface.text.presentation.PresentationReconciler) IPresentationReconciler(org.eclipse.jface.text.presentation.IPresentationReconciler) TextEvent(org.eclipse.jface.text.TextEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DiffViewer(org.eclipse.egit.ui.internal.commit.DiffViewer) SashForm(org.eclipse.swt.custom.SashForm) HyperlinkSourceViewer(org.eclipse.egit.ui.internal.dialogs.HyperlinkSourceViewer) IToolBarManager(org.eclipse.jface.action.IToolBarManager) GridData(org.eclipse.swt.layout.GridData) RevObject(org.eclipse.jgit.revwalk.RevObject) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) ControlEvent(org.eclipse.swt.events.ControlEvent) Link(org.eclipse.swt.widgets.Link)

Example 4 with RepositorySelectionProvider

use of org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider in project egit by eclipse.

the class ReflogView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    dateFormatter = PreferenceBasedDateFormatter.create();
    GridLayoutFactory.fillDefaults().applyTo(parent);
    toolkit = new FormToolkit(parent.getDisplay());
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            toolkit.dispose();
        }
    });
    form = toolkit.createForm(parent);
    Image repoImage = UIIcons.REPOSITORY.createImage();
    UIUtils.hookDisposal(form, repoImage);
    Image commitImage = UIIcons.CHANGESET.createImage();
    UIUtils.hookDisposal(form, commitImage);
    form.setImage(repoImage);
    form.setText(UIText.StagingView_NoSelectionTitle);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(form);
    toolkit.decorateFormHeading(form);
    GridLayoutFactory.fillDefaults().applyTo(form.getBody());
    Composite tableComposite = toolkit.createComposite(form.getBody());
    tableComposite.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tableComposite);
    final TreeColumnLayout layout = new TreeColumnLayout();
    FilteredTree filteredTree = new FilteredTree(tableComposite, SWT.NONE | SWT.BORDER | SWT.FULL_SELECTION, new PatternFilter(), true) {

        @Override
        protected void createControl(Composite composite, int treeStyle) {
            super.createControl(composite, treeStyle);
            treeComposite.setLayout(layout);
        }
    };
    toolkit.adapt(filteredTree);
    refLogTableTreeViewer = filteredTree.getViewer();
    refLogTableTreeViewer.getTree().setLinesVisible(true);
    refLogTableTreeViewer.getTree().setHeaderVisible(true);
    refLogTableTreeViewer.setContentProvider(new ReflogViewContentProvider());
    ColumnViewerToolTipSupport.enableFor(refLogTableTreeViewer);
    TreeViewerColumn toColumn = createColumn(layout, UIText.ReflogView_CommitColumnHeader, 10, SWT.LEFT);
    toColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ReflogEntry) {
                final ReflogEntry entry = (ReflogEntry) element;
                return entry.getNewId().abbreviate(7).name();
            }
            return null;
        }

        @Override
        public String getToolTipText(Object element) {
            if (element instanceof ReflogEntry) {
                final ReflogEntry entry = (ReflogEntry) element;
                return entry.getNewId().name();
            }
            return null;
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof ReflogEntry) {
                return commitImage;
            }
            return null;
        }
    });
    TreeViewerColumn commitMessageColumn = createColumn(layout, UIText.ReflogView_CommitMessageColumnHeader, 40, SWT.LEFT);
    commitMessageColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ReflogEntry) {
                final ReflogEntry entry = (ReflogEntry) element;
                RevCommit c = getCommit(entry);
                // $NON-NLS-1$
                return c == null ? "" : c.getShortMessage();
            } else if (element instanceof IWorkbenchAdapter) {
                return ((IWorkbenchAdapter) element).getLabel(element);
            }
            return null;
        }

        private RevCommit getCommit(final ReflogEntry entry) {
            try (RevWalk walk = new RevWalk(getRepository())) {
                walk.setRetainBody(true);
                return walk.parseCommit(entry.getNewId());
            } catch (IOException ignored) {
                // ignore
                return null;
            }
        }
    });
    TreeViewerColumn dateColumn = createColumn(layout, UIText.ReflogView_DateColumnHeader, 15, SWT.LEFT);
    dateColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ReflogEntry) {
                final ReflogEntry entry = (ReflogEntry) element;
                final PersonIdent who = entry.getWho();
                return dateFormatter.formatDate(who);
            }
            return null;
        }

        @Override
        public Image getImage(Object element) {
            return null;
        }
    });
    TreeViewerColumn messageColumn = createColumn(layout, UIText.ReflogView_MessageColumnHeader, 40, SWT.LEFT);
    messageColumn.setLabelProvider(new ColumnLabelProvider() {

        private ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources());

        @Override
        public String getText(Object element) {
            if (element instanceof ReflogEntry) {
                final ReflogEntry entry = (ReflogEntry) element;
                return entry.getComment();
            }
            return null;
        }

        @Override
        public Image getImage(Object element) {
            if (!(element instanceof ReflogEntry)) {
                return null;
            }
            String comment = ((ReflogEntry) element).getComment();
            if (// $NON-NLS-1$ //$NON-NLS-2$
            comment.startsWith("commit:") || comment.startsWith("commit (initial):"))
                return (Image) resourceManager.get(UIIcons.COMMIT);
            if (// $NON-NLS-1$
            comment.startsWith("commit (amend):"))
                return (Image) resourceManager.get(UIIcons.AMEND_COMMIT);
            if (// $NON-NLS-1$
            comment.startsWith("pull"))
                return (Image) resourceManager.get(UIIcons.PULL);
            if (// $NON-NLS-1$
            comment.startsWith("clone"))
                return (Image) resourceManager.get(UIIcons.CLONEGIT);
            if (// $NON-NLS-1$
            comment.startsWith("rebase"))
                return (Image) resourceManager.get(UIIcons.REBASE);
            if (// $NON-NLS-1$
            comment.startsWith("merge"))
                return (Image) resourceManager.get(UIIcons.MERGE);
            if (// $NON-NLS-1$
            comment.startsWith("fetch"))
                return (Image) resourceManager.get(UIIcons.FETCH);
            if (// $NON-NLS-1$
            comment.startsWith("branch"))
                return (Image) resourceManager.get(UIIcons.CREATE_BRANCH);
            if (// $NON-NLS-1$
            comment.startsWith("checkout"))
                return (Image) resourceManager.get(UIIcons.CHECKOUT);
            return null;
        }

        @Override
        public void dispose() {
            resourceManager.dispose();
            super.dispose();
        }
    });
    new OpenAndLinkWithEditorHelper(refLogTableTreeViewer) {

        @Override
        protected void linkToEditor(ISelection selection) {
        // Not supported
        }

        @Override
        protected void open(ISelection sel, boolean activate) {
            handleOpen(sel, OpenStrategy.activateOnOpen());
        }

        @Override
        protected void activate(ISelection selection) {
            handleOpen(selection, true);
        }

        private void handleOpen(ISelection selection, boolean activateOnOpen) {
            if (selection instanceof IStructuredSelection)
                if (selection.isEmpty())
                    return;
            Repository repo = getRepository();
            if (repo == null)
                return;
            try (RevWalk walk = new RevWalk(repo)) {
                for (Object element : ((IStructuredSelection) selection).toArray()) {
                    ReflogEntry entry = (ReflogEntry) element;
                    ObjectId id = entry.getNewId();
                    if (id == null || id.equals(ObjectId.zeroId()))
                        id = entry.getOldId();
                    if (id != null && !id.equals(ObjectId.zeroId()))
                        CommitEditor.openQuiet(new RepositoryCommit(repo, walk.parseCommit(id)), activateOnOpen);
                }
            } catch (IOException e) {
                Activator.logError(UIText.ReflogView_ErrorOnOpenCommit, e);
            }
        }
    };
    uiPrefsListener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            String property = event.getProperty();
            if (UIPreferences.DATE_FORMAT.equals(property) || UIPreferences.DATE_FORMAT_CHOICE.equals(property)) {
                dateFormatter = PreferenceBasedDateFormatter.create();
                refLogTableTreeViewer.refresh();
            }
        }
    };
    Activator.getDefault().getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
    selectionChangedListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (part instanceof IEditorPart) {
                IEditorInput input = ((IEditorPart) part).getEditorInput();
                if (input instanceof IFileEditorInput)
                    reactOnSelection(new StructuredSelection(((IFileEditorInput) input).getFile()));
            } else
                reactOnSelection(selection);
        }
    };
    IWorkbenchPartSite site = getSite();
    ISelectionService service = CommonUtils.getService(site, ISelectionService.class);
    service.addPostSelectionListener(selectionChangedListener);
    // Use current selection to populate reflog view
    UIUtils.notifySelectionChangedWithCurrentSelection(selectionChangedListener, site);
    site.setSelectionProvider(new RepositorySelectionProvider(refLogTableTreeViewer, () -> getRepository()));
    addRefsChangedListener = Repository.getGlobalListenerList().addRefsChangedListener(this);
    // Toolbar
    IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
    switchRepositoriesAction = new RepositoryToolbarAction(false, () -> getRepository(), repo -> reactOnSelection(new StructuredSelection(repo)));
    toolbar.add(switchRepositoriesAction);
    getViewSite().getActionBars().updateActionBars();
    // register context menu
    MenuManager menuManager = new MenuManager();
    menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    Tree tree = refLogTableTreeViewer.getTree();
    tree.setMenu(menuManager.createContextMenu(tree));
    MenuManager resetManager = ResetMenu.createMenu(getSite());
    menuManager.add(resetManager);
    getSite().registerContextMenu(POPUP_MENU_ID, menuManager, refLogTableTreeViewer);
}
Also used : OpenAndLinkWithEditorHelper(org.eclipse.ui.OpenAndLinkWithEditorHelper) AdapterUtils(org.eclipse.egit.core.AdapterUtils) DisposeEvent(org.eclipse.swt.events.DisposeEvent) UIPreferences(org.eclipse.egit.ui.UIPreferences) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ResourceManager(org.eclipse.jface.resource.ResourceManager) DisposeListener(org.eclipse.swt.events.DisposeListener) IToolBarManager(org.eclipse.jface.action.IToolBarManager) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) CommitEditor(org.eclipse.egit.ui.internal.commit.CommitEditor) RepositoryState(org.eclipse.jgit.lib.RepositoryState) OpenAndLinkWithEditorHelper(org.eclipse.ui.OpenAndLinkWithEditorHelper) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ISelectionListener(org.eclipse.ui.ISelectionListener) Composite(org.eclipse.swt.widgets.Composite) PreferenceBasedDateFormatter(org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbenchAction(org.eclipse.ui.actions.ActionFactory.IWorkbenchAction) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) TreeColumn(org.eclipse.swt.widgets.TreeColumn) RefsChangedListener(org.eclipse.jgit.events.RefsChangedListener) Separator(org.eclipse.jface.action.Separator) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) MenuManager(org.eclipse.jface.action.MenuManager) Constants(org.eclipse.jgit.lib.Constants) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ResetMenu(org.eclipse.egit.ui.internal.actions.ResetMenu) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) ListenerHandle(org.eclipse.jgit.events.ListenerHandle) OpenStrategy(org.eclipse.jface.util.OpenStrategy) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Window(org.eclipse.jface.window.Window) UIText(org.eclipse.egit.ui.internal.UIText) ReflogInput(org.eclipse.egit.ui.internal.reflog.ReflogViewContentProvider.ReflogInput) Tree(org.eclipse.swt.widgets.Tree) IFormColors(org.eclipse.ui.forms.IFormColors) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IShowInTarget(org.eclipse.ui.part.IShowInTarget) UIIcons(org.eclipse.egit.ui.internal.UIIcons) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelectionService(org.eclipse.ui.ISelectionService) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) ViewPart(org.eclipse.ui.part.ViewPart) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Activator(org.eclipse.egit.ui.Activator) Image(org.eclipse.swt.graphics.Image) JFaceResources(org.eclipse.jface.resource.JFaceResources) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ShowInContext(org.eclipse.ui.part.ShowInContext) ReflogEntry(org.eclipse.jgit.lib.ReflogEntry) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) IWorkbenchActionConstants(org.eclipse.ui.IWorkbenchActionConstants) ControlContribution(org.eclipse.jface.action.ControlContribution) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) RefsChangedEvent(org.eclipse.jgit.events.RefsChangedEvent) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) IOException(java.io.IOException) CommonUtils(org.eclipse.egit.ui.internal.CommonUtils) ObjectId(org.eclipse.jgit.lib.ObjectId) Form(org.eclipse.ui.forms.widgets.Form) RowLayout(org.eclipse.swt.layout.RowLayout) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) IContextService(org.eclipse.ui.contexts.IContextService) IResource(org.eclipse.core.resources.IResource) UIUtils(org.eclipse.egit.ui.UIUtils) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter) Repository(org.eclipse.jgit.lib.Repository) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) DisposeListener(org.eclipse.swt.events.DisposeListener) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) RepositorySelectionProvider(org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Image(org.eclipse.swt.graphics.Image) ISelectionListener(org.eclipse.ui.ISelectionListener) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ReflogEntry(org.eclipse.jgit.lib.ReflogEntry) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IFileEditorInput(org.eclipse.ui.IFileEditorInput) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) Tree(org.eclipse.swt.widgets.Tree) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) RepositoryToolbarAction(org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) ObjectId(org.eclipse.jgit.lib.ObjectId) IOException(java.io.IOException) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) IEditorPart(org.eclipse.ui.IEditorPart) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) Repository(org.eclipse.jgit.lib.Repository) PersonIdent(org.eclipse.jgit.lib.PersonIdent) IToolBarManager(org.eclipse.jface.action.IToolBarManager) IWorkbenchAdapter(org.eclipse.ui.model.IWorkbenchAdapter) MenuManager(org.eclipse.jface.action.MenuManager) IEditorInput(org.eclipse.ui.IEditorInput) Separator(org.eclipse.jface.action.Separator)

Aggregations

RepositorySelectionProvider (org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider)4 IToolBarManager (org.eclipse.jface.action.IToolBarManager)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IResource (org.eclipse.core.resources.IResource)3 AdapterUtils (org.eclipse.egit.core.AdapterUtils)3 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)3 Activator (org.eclipse.egit.ui.Activator)3 UIPreferences (org.eclipse.egit.ui.UIPreferences)3 UIUtils (org.eclipse.egit.ui.UIUtils)3 CommonUtils (org.eclipse.egit.ui.internal.CommonUtils)3 UIIcons (org.eclipse.egit.ui.internal.UIIcons)3 UIText (org.eclipse.egit.ui.internal.UIText)3 RepositoryToolbarAction (org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction)3 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)3 MenuManager (org.eclipse.jface.action.MenuManager)3 Separator (org.eclipse.jface.action.Separator)3 ISelection (org.eclipse.jface.viewers.ISelection)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 GridLayout (org.eclipse.swt.layout.GridLayout)3