Search in sources :

Example 1 with PreferenceEntry

use of org.eclipse.pde.spy.preferences.model.PreferenceEntry in project eclipse.pde by eclipse-pde.

the class PreferenceSpyPart method preferenceChanged.

@Inject
@Optional
public void preferenceChanged(@UIEventTopic(PreferenceSpyEventTopics.PREFERENCESPY_PREFERENCE_CHANGED) PreferenceChangeEvent event) {
    PreferenceNodeEntry preferenceNodeEntry = preferenceEntryManager.getRecentPreferenceNodeEntry(event.getNode().absolutePath());
    PreferenceEntry preferenceEntry = new PreferenceEntry(event.getNode().absolutePath(), event.getKey());
    preferenceEntry.setRecentlyChanged(true);
    if (null == preferenceNodeEntry) {
        preferenceNodeEntry = new PreferenceNodeEntry(event.getNode().absolutePath());
        preferenceNodeEntry.setRecentlyChanged(true);
        preferenceNodeEntry.addChildren(preferenceEntry);
        preferenceEntry.setParent(preferenceNodeEntry);
        preferenceEntryManager.addChildren(preferenceNodeEntry);
        filteredTree.getViewer().setInput(preferenceEntryManager);
        preferenceEntryManager.putRecentPreferenceEntry(event.getNode().absolutePath(), preferenceNodeEntry);
    } else {
        preferenceEntry.setParent(preferenceNodeEntry);
        PreferenceEntry existingPreferenceEntry = findPreferenceEntry(preferenceEntry);
        if (existingPreferenceEntry != null) {
            preferenceEntry = existingPreferenceEntry;
        } else {
            preferenceNodeEntry.addChildren(preferenceEntry);
        }
    }
    preferenceEntry.setOldValue(String.valueOf(event.getOldValue()));
    preferenceEntry.setNewValue(String.valueOf(event.getNewValue()));
    long currentTimeMillis = System.currentTimeMillis();
    preferenceEntry.setTime(currentTimeMillis);
    preferenceEntry.getParent().setTime(currentTimeMillis);
    filteredTree.getViewer().refresh();
}
Also used : PreferenceNodeEntry(org.eclipse.pde.spy.preferences.model.PreferenceNodeEntry) PreferenceEntry(org.eclipse.pde.spy.preferences.model.PreferenceEntry) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Example 2 with PreferenceEntry

use of org.eclipse.pde.spy.preferences.model.PreferenceEntry in project eclipse.pde by eclipse-pde.

the class PreferenceSpyPart method DeletePreferenceEntries.

@Inject
@Optional
public void DeletePreferenceEntries(@UIEventTopic(PreferenceSpyEventTopics.PREFERENCESPY_PREFERENCE_ENTRIES_DELETE) List<PreferenceEntry> preferenceEntries) {
    if (preferenceEntries != null && !preferenceEntries.isEmpty()) {
        for (PreferenceEntry preferenceEntry : preferenceEntries) {
            preferenceEntryManager.removeChildren(preferenceEntry);
        }
        preferenceEntryManager.removeChildren(preferenceEntries);
        filteredTree.getViewer().refresh();
    }
}
Also used : PreferenceEntry(org.eclipse.pde.spy.preferences.model.PreferenceEntry) Inject(javax.inject.Inject) Optional(org.eclipse.e4.core.di.annotations.Optional)

Example 3 with PreferenceEntry

use of org.eclipse.pde.spy.preferences.model.PreferenceEntry in project eclipse.pde by eclipse-pde.

the class PreferenceSpyPart method postConstruct.

@SuppressWarnings("unchecked")
@PostConstruct
public void postConstruct(Composite parent, final ESelectionService selectionService, EModelService modelService, MWindow window) {
    preferenceEntryManager = new PreferenceEntryManager();
    PreferenceEntryPatternFilter patternFilter = new PreferenceEntryPatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    filteredTree = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter);
    Tree table = filteredTree.getViewer().getTree();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    filteredTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                ArrayList<PreferenceEntry> preferenceEntries = new ArrayList<PreferenceEntry>(((IStructuredSelection) selection).toList());
                selectionService.setSelection(preferenceEntries);
            }
        }
    });
    createColumn(Fields.nodePath, Messages.PreferenceSpyPart_Nodepath, 300);
    createColumn(Fields.key, Messages.PreferenceSpyPart_Key, 300);
    createColumn(Fields.oldValue, Messages.PreferenceSpyPart_Old_Value, 150);
    createColumn(Fields.newValue, Messages.PreferenceSpyPart_New_Value, 150);
    filteredTree.getViewer().setComparator(new PreferenceEntryViewerComparator());
    FontDescriptor fontDescriptor = getBoldFontDescriptor();
    Realm realm = DisplayRealm.getRealm(filteredTree.getViewer().getControl().getDisplay());
    PreferenceEntriesContentProvider contentProvider = new PreferenceEntriesContentProvider(BeanProperties.set("preferenceEntries", PreferenceNodeEntry.class).setFactory(realm), null);
    contentProvider.setHierarchicalLayout(hierarchicalLayoutPreference);
    filteredTree.getViewer().setContentProvider(contentProvider);
    filteredTree.getViewer().setLabelProvider(new PreferenceMapLabelProvider(fontDescriptor, Properties.observeEach(contentProvider.getKnownElements(), BeanProperties.values(PreferenceEntry.class, "nodePath", "key", "oldValue", "newValue"))));
    filteredTree.getViewer().setInput(preferenceEntryManager);
}
Also used : PreferenceEntriesContentProvider(org.eclipse.pde.spy.preferences.viewer.PreferenceEntriesContentProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.e4.ui.dialogs.filteredtree.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PreferenceMapLabelProvider(org.eclipse.pde.spy.preferences.viewer.PreferenceMapLabelProvider) PreferenceEntryManager(org.eclipse.pde.spy.preferences.model.PreferenceEntryManager) PreferenceEntryPatternFilter(org.eclipse.pde.spy.preferences.model.PreferenceEntryPatternFilter) PreferenceEntry(org.eclipse.pde.spy.preferences.model.PreferenceEntry) ISelection(org.eclipse.jface.viewers.ISelection) FilteredTree(org.eclipse.e4.ui.dialogs.filteredtree.FilteredTree) Tree(org.eclipse.swt.widgets.Tree) PreferenceEntryViewerComparator(org.eclipse.pde.spy.preferences.viewer.PreferenceEntryViewerComparator) Realm(org.eclipse.core.databinding.observable.Realm) DisplayRealm(org.eclipse.jface.databinding.swt.DisplayRealm) FontDescriptor(org.eclipse.jface.resource.FontDescriptor) PostConstruct(javax.annotation.PostConstruct)

Example 4 with PreferenceEntry

use of org.eclipse.pde.spy.preferences.model.PreferenceEntry in project eclipse.pde by eclipse-pde.

the class PreferenceEntryViewerComparator method compare.

@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    if (e1 instanceof PreferenceEntry && e2 instanceof PreferenceEntry) {
        PreferenceEntry entry1 = (PreferenceEntry) e1;
        PreferenceEntry entry2 = (PreferenceEntry) e2;
        long time = entry1.getTime();
        long time2 = entry2.getTime();
        if (time != 0 && time2 != 0) {
            return (int) (time2 - time);
        }
    }
    return super.compare(viewer, e1, e2);
}
Also used : PreferenceEntry(org.eclipse.pde.spy.preferences.model.PreferenceEntry)

Aggregations

PreferenceEntry (org.eclipse.pde.spy.preferences.model.PreferenceEntry)4 Inject (javax.inject.Inject)2 Optional (org.eclipse.e4.core.di.annotations.Optional)2 ArrayList (java.util.ArrayList)1 PostConstruct (javax.annotation.PostConstruct)1 Realm (org.eclipse.core.databinding.observable.Realm)1 FilteredTree (org.eclipse.e4.ui.dialogs.filteredtree.FilteredTree)1 DisplayRealm (org.eclipse.jface.databinding.swt.DisplayRealm)1 FontDescriptor (org.eclipse.jface.resource.FontDescriptor)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 PreferenceEntryManager (org.eclipse.pde.spy.preferences.model.PreferenceEntryManager)1 PreferenceEntryPatternFilter (org.eclipse.pde.spy.preferences.model.PreferenceEntryPatternFilter)1 PreferenceNodeEntry (org.eclipse.pde.spy.preferences.model.PreferenceNodeEntry)1 PreferenceEntriesContentProvider (org.eclipse.pde.spy.preferences.viewer.PreferenceEntriesContentProvider)1 PreferenceEntryViewerComparator (org.eclipse.pde.spy.preferences.viewer.PreferenceEntryViewerComparator)1 PreferenceMapLabelProvider (org.eclipse.pde.spy.preferences.viewer.PreferenceMapLabelProvider)1 Tree (org.eclipse.swt.widgets.Tree)1