use of org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction 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));
}
use of org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction in project egit by eclipse.
the class StagingView method updateToolbar.
private void updateToolbar() {
ControlContribution controlContribution = new ControlContribution(// $NON-NLS-1$
"StagingView.searchText") {
@Override
protected Control createControl(Composite parent) {
Composite toolbarComposite = toolkit.createComposite(parent, SWT.NONE);
toolbarComposite.setBackground(null);
GridLayout headLayout = new GridLayout();
headLayout.numColumns = 2;
headLayout.marginHeight = 0;
headLayout.marginWidth = 0;
headLayout.marginTop = 0;
headLayout.marginBottom = 0;
headLayout.marginLeft = 0;
headLayout.marginRight = 0;
toolbarComposite.setLayout(headLayout);
filterText = new Text(toolbarComposite, SWT.SEARCH | SWT.ICON_CANCEL | SWT.ICON_SEARCH);
filterText.setMessage(UIText.StagingView_Find);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = 150;
filterText.setLayoutData(data);
final Display display = Display.getCurrent();
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
filterPattern = wildcardToRegex(filterText.getText());
final StagingViewSearchThread searchThread = new StagingViewSearchThread(StagingView.this);
display.timerExec(200, new Runnable() {
@Override
public void run() {
searchThread.start();
}
});
}
});
return toolbarComposite;
}
};
IActionBars actionBars = getViewSite().getActionBars();
IToolBarManager toolbar = actionBars.getToolBarManager();
toolbar.add(controlContribution);
refreshAction = new Action(UIText.StagingView_Refresh, IAction.AS_PUSH_BUTTON) {
@Override
public void run() {
if (cacheEntry != null) {
schedule(cacheEntry.createRefreshResourcesAndIndexDiffJob(), false);
}
}
};
refreshAction.setImageDescriptor(UIIcons.ELCL16_REFRESH);
toolbar.add(refreshAction);
// link with selection
Action linkSelectionAction = new BooleanPrefAction((IPersistentPreferenceStore) getPreferenceStore(), UIPreferences.STAGING_VIEW_SYNC_SELECTION, UIText.StagingView_LinkSelection) {
@Override
public void apply(boolean value) {
reactOnSelection = value;
}
};
linkSelectionAction.setImageDescriptor(UIIcons.ELCL16_SYNCED);
toolbar.add(linkSelectionAction);
toolbar.add(new Separator());
switchRepositoriesAction = new RepositoryToolbarAction(false, () -> realRepository, repo -> {
if (realRepository != repo) {
reload(repo);
}
});
toolbar.add(switchRepositoriesAction);
compareModeAction = new Action(UIText.StagingView_CompareMode, IAction.AS_CHECK_BOX) {
@Override
public void run() {
getPreferenceStore().setValue(UIPreferences.STAGING_VIEW_COMPARE_MODE, isChecked());
}
};
compareModeAction.setImageDescriptor(UIIcons.ELCL16_COMPARE_VIEW);
compareModeAction.setChecked(getPreferenceStore().getBoolean(UIPreferences.STAGING_VIEW_COMPARE_MODE));
toolbar.add(compareModeAction);
toolbar.add(new Separator());
openNewCommitsAction = new Action(UIText.StagingView_OpenNewCommits, IAction.AS_CHECK_BOX) {
@Override
public void run() {
getPreferenceStore().setValue(UIPreferences.STAGING_VIEW_SHOW_NEW_COMMITS, isChecked());
}
};
openNewCommitsAction.setChecked(getPreferenceStore().getBoolean(UIPreferences.STAGING_VIEW_SHOW_NEW_COMMITS));
columnLayoutAction = new Action(UIText.StagingView_ColumnLayout, IAction.AS_CHECK_BOX) {
@Override
public void run() {
getPreferenceStore().setValue(UIPreferences.STAGING_VIEW_COLUMN_LAYOUT, isChecked());
stagingSashForm.setOrientation(isChecked() ? SWT.HORIZONTAL : SWT.VERTICAL);
}
};
columnLayoutAction.setChecked(getPreferenceStore().getBoolean(UIPreferences.STAGING_VIEW_COLUMN_LAYOUT));
fileNameModeAction = new Action(UIText.StagingView_ShowFileNamesFirst, IAction.AS_CHECK_BOX) {
@Override
public void run() {
final boolean enable = isChecked();
getLabelProvider(stagedViewer).setFileNameMode(enable);
getLabelProvider(unstagedViewer).setFileNameMode(enable);
getContentProvider(stagedViewer).setFileNameMode(enable);
getContentProvider(unstagedViewer).setFileNameMode(enable);
StagingEntryComparator comparator = (StagingEntryComparator) unstagedViewer.getComparator();
comparator.setFileNamesFirst(enable);
comparator = (StagingEntryComparator) stagedViewer.getComparator();
comparator.setFileNamesFirst(enable);
getPreferenceStore().setValue(UIPreferences.STAGING_VIEW_FILENAME_MODE, enable);
refreshViewersPreservingExpandedElements();
}
};
fileNameModeAction.setChecked(getPreferenceStore().getBoolean(UIPreferences.STAGING_VIEW_FILENAME_MODE));
IMenuManager dropdownMenu = actionBars.getMenuManager();
MenuManager presentationMenu = new MenuManager(UIText.StagingView_Presentation);
listPresentationAction = new Action(UIText.StagingView_List, IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
if (!isChecked()) {
return;
}
switchToListMode();
refreshViewers();
}
};
listPresentationAction.setImageDescriptor(UIIcons.FLAT);
presentationMenu.add(listPresentationAction);
treePresentationAction = new Action(UIText.StagingView_Tree, IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
if (!isChecked()) {
return;
}
presentation = Presentation.TREE;
setPresentation(presentation, false);
listPresentationAction.setChecked(false);
compactTreePresentationAction.setChecked(false);
setExpandCollapseActionsVisible(false, isExpandAllowed(false), true);
setExpandCollapseActionsVisible(true, isExpandAllowed(true), true);
refreshViewers();
}
};
treePresentationAction.setImageDescriptor(UIIcons.HIERARCHY);
presentationMenu.add(treePresentationAction);
compactTreePresentationAction = new Action(UIText.StagingView_CompactTree, IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
if (!isChecked()) {
return;
}
switchToCompactModeInternal(false);
refreshViewers();
}
};
compactTreePresentationAction.setImageDescriptor(UIIcons.COMPACT);
presentationMenu.add(compactTreePresentationAction);
presentation = readPresentation(UIPreferences.STAGING_VIEW_PRESENTATION, Presentation.LIST);
switch(presentation) {
case LIST:
listPresentationAction.setChecked(true);
setExpandCollapseActionsVisible(false, false, false);
setExpandCollapseActionsVisible(true, false, false);
break;
case TREE:
treePresentationAction.setChecked(true);
break;
case COMPACT_TREE:
compactTreePresentationAction.setChecked(true);
break;
default:
break;
}
dropdownMenu.add(presentationMenu);
dropdownMenu.add(new Separator());
dropdownMenu.add(openNewCommitsAction);
dropdownMenu.add(columnLayoutAction);
dropdownMenu.add(fileNameModeAction);
dropdownMenu.add(compareModeAction);
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), new GlobalDeleteActionHandler());
// For the normal resource undo/redo actions to be active, so that files
// deleted via the "Delete" action in the staging view can be restored.
IUndoContext workspaceContext = AdapterUtils.adapt(ResourcesPlugin.getWorkspace(), IUndoContext.class);
undoRedoActionGroup = new UndoRedoActionGroup(getViewSite(), workspaceContext, true);
undoRedoActionGroup.fillActionBars(actionBars);
actionBars.updateActionBars();
}
use of org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction 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);
}
Aggregations