use of org.eclipse.ui.ISelectionService 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);
}
use of org.eclipse.ui.ISelectionService in project egit by eclipse.
the class GitSynchronizeWizard method getSelectedResources.
private Set<IResource> getSelectedResources(Repository repo) {
ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
Set<IResource> result = new HashSet<>();
IStructuredSelection sel = (IStructuredSelection) selection;
if (sel.size() == 0)
return null;
File workTree = repo.getWorkTree();
for (Object o : sel.toArray()) {
if (o == null) {
continue;
}
IResource res = AdapterUtils.adaptToAnyResource(o);
if (res == null) {
continue;
}
int type = res.getType();
if (type == IResource.FOLDER) {
RepositoryMapping mapping = RepositoryMapping.getMapping(res);
if (mapping == null) {
continue;
}
Repository selRepo = mapping.getRepository();
if (workTree.equals(selRepo.getWorkTree()))
result.add(res);
}
}
return result;
}
return null;
}
use of org.eclipse.ui.ISelectionService 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);
}
use of org.eclipse.ui.ISelectionService in project egit by eclipse.
the class ReflogView method dispose.
@Override
public void dispose() {
super.dispose();
ISelectionService service = CommonUtils.getService(getSite(), ISelectionService.class);
service.removePostSelectionListener(selectionChangedListener);
if (addRefsChangedListener != null) {
addRefsChangedListener.remove();
}
Activator.getDefault().getPreferenceStore().removePropertyChangeListener(uiPrefsListener);
if (switchRepositoriesAction != null) {
switchRepositoriesAction.dispose();
switchRepositoriesAction = null;
}
}
use of org.eclipse.ui.ISelectionService in project egit by eclipse.
the class RepositoriesView method dispose.
@Override
public void dispose() {
// make sure to cancel the refresh job
if (this.scheduledJob != null) {
this.scheduledJob.cancel();
this.scheduledJob = null;
}
refreshUiJob.cancel();
repositoryUtil.getPreferences().removePreferenceChangeListener(configurationListener);
ISelectionService srv = CommonUtils.getService(getSite(), ISelectionService.class);
srv.removePostSelectionListener(selectionChangedListener);
// remove RepositoryChangedListener
unregisterRepositoryListener();
repositories.clear();
super.dispose();
}
Aggregations