use of org.eclipse.ui.model.IWorkbenchAdapter in project netxms by netxms.
the class UserAdapterFactory method getAdapter.
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adapterType == IWorkbenchAdapter.class) {
// NXCUser
if (adaptableObject instanceof User) {
return new IWorkbenchAdapter() {
@Override
public Object[] getChildren(Object o) {
return null;
}
@Override
public ImageDescriptor getImageDescriptor(Object object) {
// $NON-NLS-1$
return Activator.getImageDescriptor("icons/user.png");
}
@Override
public String getLabel(Object o) {
return ((User) o).getName();
}
@Override
public Object getParent(Object o) {
return null;
}
};
}
// NXCUserGroup
if (adaptableObject instanceof UserGroup) {
return new IWorkbenchAdapter() {
@Override
public Object[] getChildren(Object o) {
long[] members = ((UserGroup) o).getMembers();
AbstractUserObject[] childrens = new User[members.length];
for (int i = 0; i < members.length; i++) childrens[i] = ConsoleSharedData.getSession().findUserDBObjectById(members[i]);
return childrens;
}
@Override
public ImageDescriptor getImageDescriptor(Object object) {
// $NON-NLS-1$
return Activator.getImageDescriptor("icons/group.png");
}
@Override
public String getLabel(Object o) {
return ((UserGroup) o).getName();
}
@Override
public Object getParent(Object o) {
return null;
}
};
}
// AccessListElement
if (adaptableObject instanceof AbstractAccessListElement) {
return new IWorkbenchAdapter() {
@Override
public Object[] getChildren(Object o) {
return null;
}
@Override
public ImageDescriptor getImageDescriptor(Object object) {
long userId = ((AbstractAccessListElement) object).getUserId();
// $NON-NLS-1$ //$NON-NLS-2$
return Activator.getImageDescriptor((userId < 0x80000000L) ? "icons/user.png" : "icons/group.png");
}
@Override
public String getLabel(Object object) {
long userId = ((AbstractAccessListElement) object).getUserId();
NXCSession session = ConsoleSharedData.getSession();
AbstractUserObject dbo = session.findUserDBObjectById(userId);
// $NON-NLS-1$ //$NON-NLS-2$
return (dbo != null) ? dbo.getName() : ("{" + Long.toString(userId) + "}");
}
@Override
public Object getParent(Object o) {
return null;
}
};
}
}
return null;
}
use of org.eclipse.ui.model.IWorkbenchAdapter in project netxms by netxms.
the class ObjectToolsAdapterFactory method getAdapter.
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adaptableObject.getClass() != ObjectTool.class)
return null;
// Adapt to tool details
if (adapterType == ObjectToolDetails.class) {
final long toolId = ((ObjectTool) adaptableObject).getId();
ObjectToolDetails details = cache.get(toolId);
if (details == null) {
ToolDetailLoader job = new ToolDetailLoader(toolId, PlatformUI.getWorkbench().getDisplay());
IProgressService service = PlatformUI.getWorkbench().getProgressService();
try {
service.busyCursorWhile(job);
details = job.getResult();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return details;
}
// Adapt to IWorkbenchAdapter
if (adapterType == IWorkbenchAdapter.class) {
return new IWorkbenchAdapter() {
@Override
public Object getParent(Object o) {
return null;
}
@Override
public String getLabel(Object o) {
return ((ObjectTool) o).getDisplayName();
}
@Override
public ImageDescriptor getImageDescriptor(Object object) {
return null;
}
@Override
public Object[] getChildren(Object o) {
return null;
}
};
}
return null;
}
use of org.eclipse.ui.model.IWorkbenchAdapter 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.model.IWorkbenchAdapter in project ecf by eclipse.
the class WorkbenchLabelProvider method getText.
/*
* (non-Javadoc) Method declared on ILabelProvider
*/
public final String getText(Object element) {
// query the element for its label
IWorkbenchAdapter adapter = getAdapter(element);
if (adapter == null)
// $NON-NLS-1$
return "";
String label = adapter.getLabel(element);
// return the decorated label
return decorateText(label, element);
}
use of org.eclipse.ui.model.IWorkbenchAdapter in project ecf by eclipse.
the class WorkbenchLabelProvider method getImage.
/*
* (non-Javadoc) Method declared on ILabelProvider
*/
public final Image getImage(Object element) {
// obtain the base image by querying the element
IWorkbenchAdapter adapter = getAdapter(element);
if (adapter == null)
return null;
ImageDescriptor descriptor = adapter.getImageDescriptor(element);
if (descriptor == null)
return null;
// add any annotations to the image descriptor
descriptor = decorateImage(descriptor, element);
/*
* Image image = (Image)
* SWTResourceUtil.getImageTable().get(descriptor); if (image == null) {
* image = descriptor.createImage();
* SWTResourceUtil.getImageTable().put(descriptor, image); }
*/
Image image = descriptor.createImage();
return image;
}
Aggregations