use of org.eclipse.jface.resource.ResourceManager in project liferay-ide by liferay.
the class WorkingSetGroup method _createControl.
private void _createControl(Composite container) {
addToWorkingSetButton = new Button(container, SWT.CHECK);
GridData gd_addToWorkingSetButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1);
gd_addToWorkingSetButton.verticalIndent = 12;
addToWorkingSetButton.setLayoutData(gd_addToWorkingSetButton);
addToWorkingSetButton.setSelection(true);
addToWorkingSetButton.setData("name", "addToWorkingSetButton");
addToWorkingSetButton.setText("Add project to working set");
addToWorkingSetButton.setSelection(false);
final Label workingsetLabel = new Label(container, SWT.NONE);
GridData gd_workingsetLabel = new GridData();
gd_workingsetLabel.horizontalIndent = 10;
workingsetLabel.setLayoutData(gd_workingsetLabel);
workingsetLabel.setEnabled(false);
workingsetLabel.setData("name", "workingsetLabel");
workingsetLabel.setText("Working set:");
Combo workingsetCombo = new Combo(container, SWT.READ_ONLY);
workingsetCombo.setEnabled(false);
workingsetCombo.setData("name", "workingsetCombo");
workingsetCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
_workingsetComboViewer = new ComboViewer(workingsetCombo);
_workingsetComboViewer.setContentProvider(new IStructuredContentProvider() {
public void dispose() {
}
public Object[] getElements(Object input) {
if (input instanceof IWorkingSet[]) {
return (IWorkingSet[]) input;
} else if (input instanceof List<?>) {
return new Object[] { input };
} else if (input instanceof Set<?>) {
return ((Set<?>) input).toArray();
}
return new IWorkingSet[0];
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
_workingsetComboViewer.setLabelProvider(new LabelProvider() {
public void dispose() {
_images.dispose();
super.dispose();
}
@SuppressWarnings("deprecation")
public Image getImage(Object element) {
if (element instanceof IWorkingSet) {
ImageDescriptor imageDescriptor = ((IWorkingSet) element).getImage();
if (imageDescriptor != null) {
try {
return (Image) _images.create(imageDescriptor);
} catch (DeviceResourceException dre) {
return null;
}
}
}
return super.getImage(element);
}
public String getText(Object element) {
if (element instanceof IWorkingSet) {
return ((IWorkingSet) element).getLabel();
} else if (element instanceof List<?>) {
StringBuffer sb = new StringBuffer();
for (Object o : (List<?>) element) {
if (o instanceof IWorkingSet) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(((IWorkingSet) o).getLabel());
}
}
return sb.toString();
}
return super.getText(element);
}
private ResourceManager _images = new LocalResourceManager(JFaceResources.getResources());
});
_workingsetComboViewer.setComparator(new ViewerComparator());
final Button newWorkingSetButton = new Button(container, SWT.NONE);
newWorkingSetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
newWorkingSetButton.setData("name", "configureButton");
newWorkingSetButton.setText("More...");
newWorkingSetButton.setEnabled(false);
newWorkingSetButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
IWorkingSetSelectionDialog dialog = workingSetManager.createWorkingSetSelectionDialog(_shell, true, _working_set_ids.toArray(new String[0]));
if (dialog.open() == Window.OK) {
IWorkingSet[] workingSets = dialog.getSelection();
selectWorkingSets(Arrays.asList(workingSets));
}
}
});
if (selectWorkingSets(_workingSets)) {
addToWorkingSetButton.setSelection(true);
workingsetLabel.setEnabled(true);
_workingsetComboViewer.getCombo().setEnabled(true);
newWorkingSetButton.setEnabled(true);
}
addToWorkingSetButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
boolean addToWorkingingSet = addToWorkingSetButton.getSelection();
workingsetLabel.setEnabled(addToWorkingingSet);
_workingsetComboViewer.getCombo().setEnabled(addToWorkingingSet);
newWorkingSetButton.setEnabled(addToWorkingingSet);
if (addToWorkingingSet) {
updateConfiguration();
} else {
_workingSets.clear();
}
}
});
_workingsetComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
updateConfiguration();
}
});
}
use of org.eclipse.jface.resource.ResourceManager in project yamcs-studio by yamcs.
the class ConnectionsDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
parent.getShell().setText("Yamcs Server Connections");
var contentArea = (Composite) super.createDialogArea(parent);
var gl = new GridLayout();
gl.marginHeight = 0;
gl.verticalSpacing = 0;
contentArea.setLayout(gl);
ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), contentArea);
var editBar = new ToolBar(contentArea, SWT.NO_FOCUS);
addServerButton = new ToolItem(editBar, SWT.NONE);
addServerButton.setImage(resourceManager.createImage(getImageDescriptor(ConnectionsDialog.class, "icons/obj16/server_add.png")));
addServerButton.setToolTipText("Add Connection");
addServerButton.addListener(SWT.Selection, evt -> {
addServer();
updateState();
saveChanges();
});
removeServerButton = new ToolItem(editBar, SWT.NONE);
removeServerButton.setImage(resourceManager.createImage(getImageDescriptor(ConnectionsDialog.class, "icons/obj16/server_remove.png")));
removeServerButton.setToolTipText("Delete Connection");
removeServerButton.addListener(SWT.Selection, evt -> {
removeSelectedServer();
updateState();
saveChanges();
});
editBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
var sash = new SashForm(contentArea, SWT.HORIZONTAL);
sash.setLayoutData(new GridData(GridData.FILL_BOTH));
sash.setLayout(new FillLayout());
createServerPanel(sash, resourceManager);
// Create right side, but wrap it in another composite to force
// dimensions even when invisible
var detailPanelWrapper = new Composite(sash, SWT.NONE);
gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
detailPanelWrapper.setLayout(gl);
createDetailPanel(detailPanelWrapper, resourceManager);
var gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 200;
detailPanel.setLayoutData(gd);
sash.setWeights(new int[] { 70, 30 });
connections.addAll(ConnectionPreferences.getConnections());
updateState();
var lastId = ConnectionPreferences.getLastUsedConnection();
if (lastId != null) {
selectConnection(lastId);
} else {
selectFirstConnection();
}
return contentArea;
}
use of org.eclipse.jface.resource.ResourceManager in project egit by eclipse.
the class FindToolbar method createToolbar.
private void createToolbar() {
errorBackgroundColor = new Color(getDisplay(), new RGB(255, 150, 150));
ResourceManager resourceManager = Activator.getDefault().getResourceManager();
allIcon = UIIcons.getImage(resourceManager, UIIcons.SEARCH_COMMIT);
commitIdIcon = UIIcons.getImage(resourceManager, UIIcons.ELCL16_ID);
commentsIcon = UIIcons.getImage(resourceManager, UIIcons.ELCL16_COMMENTS);
authorIcon = UIIcons.getImage(resourceManager, UIIcons.ELCL16_AUTHOR);
committerIcon = UIIcons.getImage(resourceManager, UIIcons.ELCL16_COMMITTER);
branchesIcon = UIIcons.getImage(resourceManager, UIIcons.BRANCHES);
GridLayout findLayout = new GridLayout();
findLayout.marginHeight = 0;
findLayout.marginBottom = 1;
findLayout.marginWidth = 0;
findLayout.numColumns = 5;
setLayout(findLayout);
setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
patternField = new Text(this, SWT.SEARCH | SWT.ICON_CANCEL | SWT.ICON_SEARCH);
GridData findTextData = new GridData(SWT.FILL, SWT.LEFT, true, false);
findTextData.minimumWidth = 150;
patternField.setLayoutData(findTextData);
patternField.setMessage(UIText.HistoryPage_findbar_find_msg);
patternField.setTextLimit(100);
// Do _not_ set the font to JFaceResources.getDialogFont() here. It'll
// scale if changed, but the Text field may not adjust.
ToolBarManager manager = new ToolBarManager(SWT.HORIZONTAL);
findNextAction = new Action() {
@Override
public void run() {
findNext();
}
};
findNextAction.setImageDescriptor(UIIcons.ELCL16_NEXT);
findNextAction.setText(UIText.HistoryPage_findbar_next);
findNextAction.setToolTipText(UIText.FindToolbar_NextTooltip);
findNextAction.setEnabled(false);
manager.add(findNextAction);
findPreviousAction = new Action() {
@Override
public void run() {
findPrevious();
}
};
findPreviousAction.setImageDescriptor(UIIcons.ELCL16_PREVIOUS);
findPreviousAction.setText(UIText.HistoryPage_findbar_previous);
findPreviousAction.setToolTipText(UIText.FindToolbar_PreviousTooltip);
findPreviousAction.setEnabled(false);
manager.add(findPreviousAction);
final ToolBar toolBar = manager.createControl(this);
prefsDropDown = new ToolItem(toolBar, SWT.DROP_DOWN);
prefsMenu = new Menu(getShell(), SWT.POP_UP);
caseItem = new MenuItem(prefsMenu, SWT.CHECK);
caseItem.setText(UIText.HistoryPage_findbar_ignorecase);
new MenuItem(prefsMenu, SWT.SEPARATOR);
allItem = createFindInMenuItem();
allItem.setText(UIText.HistoryPage_findbar_all);
allItem.setImage(allIcon);
commentsItem = createFindInMenuItem();
commentsItem.setText(UIText.HistoryPage_findbar_comments);
commentsItem.setImage(commentsIcon);
authorItem = createFindInMenuItem();
authorItem.setText(UIText.HistoryPage_findbar_author);
authorItem.setImage(authorIcon);
commitIdItem = createFindInMenuItem();
commitIdItem.setText(UIText.HistoryPage_findbar_commit);
commitIdItem.setImage(commitIdIcon);
committerItem = createFindInMenuItem();
committerItem.setText(UIText.HistoryPage_findbar_committer);
committerItem.setImage(committerIcon);
referenceItem = createFindInMenuItem();
referenceItem.setText(UIText.HistoryPage_findbar_reference);
referenceItem.setImage(branchesIcon);
prefsDropDown.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
if (event.detail == SWT.ARROW) {
// Arrow clicked, show drop down menu
Rectangle itemBounds = prefsDropDown.getBounds();
Point point = toolBar.toDisplay(itemBounds.x, itemBounds.y + itemBounds.height);
prefsMenu.setLocation(point);
prefsMenu.setVisible(true);
} else {
// Button clicked, cycle to next option
if (allItem.getSelection())
selectFindInItem(commentsItem);
else if (commentsItem.getSelection())
selectFindInItem(authorItem);
else if (authorItem.getSelection())
selectFindInItem(commitIdItem);
else if (commitIdItem.getSelection())
selectFindInItem(committerItem);
else if (committerItem.getSelection())
selectFindInItem(referenceItem);
else if (referenceItem.getSelection())
selectFindInItem(allItem);
}
}
});
patternModifyListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
if (getSearchPattern().equals(lastSearchPattern)) {
// Don't bother if it's still the same.
return;
}
final FindToolbarJob finder = createFinder();
finder.setUser(false);
finder.schedule(200);
}
};
patternField.addModifyListener(patternModifyListener);
patternField.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
if (e.detail != SWT.ICON_CANCEL && !getSearchPattern().isEmpty()) {
// ENTER or the search icon clicked
final FindToolbarJob finder = createFinder();
finder.setUser(false);
finder.schedule();
}
}
});
patternField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.ARROW_DOWN) {
findNext();
} else if (e.keyCode == SWT.ARROW_UP) {
findPrevious();
}
}
});
caseItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
store.setValue(UIPreferences.FINDTOOLBAR_IGNORE_CASE, caseItem.getSelection());
if (store.needsSaving()) {
try {
store.save();
} catch (IOException e1) {
Activator.handleError(e1.getMessage(), e1, false);
}
}
clear();
}
});
caseItem.setSelection(store.getBoolean(UIPreferences.FINDTOOLBAR_IGNORE_CASE));
int selectedPrefsItem = store.getInt(UIPreferences.FINDTOOLBAR_FIND_IN);
if (selectedPrefsItem == PREFS_FINDIN_ALL)
selectFindInItem(allItem);
else if (selectedPrefsItem == PREFS_FINDIN_COMMENTS)
selectFindInItem(commentsItem);
else if (selectedPrefsItem == PREFS_FINDIN_AUTHOR)
selectFindInItem(authorItem);
else if (selectedPrefsItem == PREFS_FINDIN_COMMITID)
selectFindInItem(commitIdItem);
else if (selectedPrefsItem == PREFS_FINDIN_COMMITTER)
selectFindInItem(committerItem);
else if (selectedPrefsItem == PREFS_FINDIN_REFERENCE)
selectFindInItem(referenceItem);
registerDisposal();
}
use of org.eclipse.jface.resource.ResourceManager 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