Search in sources :

Example 6 with ResourceManager

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();
        }
    });
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) Button(org.eclipse.swt.widgets.Button) DeviceResourceException(org.eclipse.jface.resource.DeviceResourceException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IWorkingSetSelectionDialog(org.eclipse.ui.dialogs.IWorkingSetSelectionDialog) List(java.util.List) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IWorkingSet(org.eclipse.ui.IWorkingSet) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 7 with ResourceManager

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;
}
Also used : SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) FillLayout(org.eclipse.swt.layout.FillLayout) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 8 with ResourceManager

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();
}
Also used : Action(org.eclipse.jface.action.Action) DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyListener(org.eclipse.swt.events.KeyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) ToolBarManager(org.eclipse.jface.action.ToolBarManager) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) ToolItem(org.eclipse.swt.widgets.ToolItem) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) MenuItem(org.eclipse.swt.widgets.MenuItem) ResourceManager(org.eclipse.jface.resource.ResourceManager) Point(org.eclipse.swt.graphics.Point) IOException(java.io.IOException) RGB(org.eclipse.swt.graphics.RGB) Point(org.eclipse.swt.graphics.Point) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 9 with ResourceManager

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);
}
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

ResourceManager (org.eclipse.jface.resource.ResourceManager)9 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)8 GridLayout (org.eclipse.swt.layout.GridLayout)7 GridData (org.eclipse.swt.layout.GridData)6 Composite (org.eclipse.swt.widgets.Composite)6 Image (org.eclipse.swt.graphics.Image)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 ToolBar (org.eclipse.swt.widgets.ToolBar)3 ToolItem (org.eclipse.swt.widgets.ToolItem)3 IOException (java.io.IOException)2 UIText (org.eclipse.egit.ui.internal.UIText)2 SashForm (org.eclipse.swt.custom.SashForm)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Button (org.eclipse.swt.widgets.Button)2 HashMap (java.util.HashMap)1 List (java.util.List)1