]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.selectionview/src/org/simantics/selectionview/StandardProperties.java
Diagram to SVG to support selection cycling
[simantics/platform.git] / bundles / org.simantics.selectionview / src / org / simantics / selectionview / StandardProperties.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.selectionview;
13
14 import java.util.Collection;
15 import java.util.HashSet;
16 import java.util.Set;
17
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.ui.IWorkbenchPartSite;
20 import org.eclipse.ui.part.IPageSite;
21 import org.simantics.browsing.ui.common.ErrorLogger;
22 import org.simantics.browsing.ui.common.views.IFilterArea;
23 import org.simantics.browsing.ui.common.views.IFilterAreaProvider;
24 import org.simantics.db.ReadGraph;
25
26 /**
27  * @author Antti Villberg
28  * 
29  * @see StandardPropertyPage
30  */
31 public class StandardProperties extends TabbedPropertyTable implements IFilterAreaProvider, IPropertyTab {
32
33     /**
34      * @param site
35      * @param pageSite
36      * @param parent
37      * @param style
38      * @param browseContexts the browse contexts to use for loading this
39      *        property table
40      * @param selectionProcessors a fixed set of selection processors, may be
41      *        <code>null</code>
42      */
43     public StandardProperties(IWorkbenchPartSite site, IPageSite pageSite, Composite parent, int style,
44             final Set<String> browseContexts, final Collection<SelectionProcessor<?, ?>> selectionProcessors) {
45         super(site, pageSite, parent, style);
46
47         final Set<SelectionProcessor<?, ?>> processors = new HashSet<SelectionProcessor<?, ?>>();
48         if (selectionProcessors != null)
49             processors.addAll(selectionProcessors);
50
51         //System.out.println("StandardProperties with contexts: " + browseContexts);
52         for (final SelectionProcessorBinding binding : SelectionProcessorBindingExtensionManager.getInstance().getBoundContributions(browseContexts)) {
53             //System.out.println("found " + binding.getProcessor());
54             processors.add(binding.getProcessor());
55         }
56
57         setSelectionProcessor(new SelectionProcessor<Object, ReadGraph>() {
58
59             @SuppressWarnings({ "rawtypes", "unchecked" })
60             @Override
61             public Collection<?> process(final Object selection, ReadGraph graph) {
62
63                 HashSet<Object> l     = new HashSet<Object>();
64                 for (SelectionProcessor p : processors) {
65                     Collection<?> c = p.process(selection, graph);
66                     if (c != null) {
67                         l.addAll(c);
68                     } else {
69                         ErrorLogger.defaultLogWarning("SelectionProcessor '" + p + "' invalidly returned null with selection '" + selection + "'", null);
70                     }
71                 }
72
73                 return l;
74
75             }
76
77         });
78     }
79
80     @Override
81     public IFilterArea getFilterArea() {
82         IPropertyTab active = getActiveTab();
83         if (!(active instanceof IFilterAreaProvider))
84             return null;
85         return ((IFilterAreaProvider) active).getFilterArea();
86     }
87
88 }