View Javadoc
1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2006</p>
22   * <p>Company: OntoText Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.preferences;
26  
27  import java.util.*;
28  import java.util.List;
29  
30  import org.eclipse.jface.preference.PreferencePage;
31  import org.eclipse.jface.resource.JFaceResources;
32  import org.eclipse.jface.viewers.*;
33  import org.eclipse.swt.SWT;
34  import org.eclipse.swt.events.SelectionAdapter;
35  import org.eclipse.swt.events.SelectionEvent;
36  import org.eclipse.swt.layout.*;
37  import org.eclipse.swt.widgets.*;
38  import org.eclipse.ui.*;
39  import org.wsmostudio.runtime.WsmoImageRegistry;
40  import org.wsmostudio.ui.WsmoUIPlugin;
41  import org.wsmostudio.ui.views.navigator.*;
42  
43  /***
44   * A preference page related to the WSMO Navigator view and especially to its
45   * extension point <code>org.wsmostudio.ui.navigator_content</code>.
46   * It determines which filter extensions will be activated in the current session
47   * of the navigator view.
48   * 
49   * @author not attributable
50   * @version $Revision: 1072 $ $Date: 2007-03-13 19:54:08 +0200 $
51   */
52  
53  public class NavigatorPage extends PreferencePage
54  implements IWorkbenchPreferencePage {
55  
56      private static final String HIDE_ATTRS_IN_TREE = "$WSMONavi$showAttr";
57  
58      private CheckboxTableViewer viewer;
59      private Button showAttrButton;
60      private List<ContentExtensionManager.FilterConfigWrapper> filters;
61      private boolean dirty = false;
62  
63      
64      public NavigatorPage() {
65          super("WSMO Navigator Preferences");
66          setPreferenceStore(WsmoUIPlugin.getDefault().getPreferenceStore());
67          filters = ContentExtensionManager.loadFilterConfigData();
68      }
69      
70      protected Control createContents(Composite parent) {
71          Group mainHolder = new Group(parent, SWT.NONE);
72          mainHolder.setLayout(new GridLayout(1, false));
73          
74          new Label(mainHolder, SWT.NONE).setText("Active Content Filters :");
75          
76          viewer = CheckboxTableViewer.newCheckList(mainHolder, SWT.BORDER);
77          viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
78          
79          viewer.setContentProvider(new ArrayContentProvider() {
80              public Object[] getElements(Object inputElement) {
81                  if (inputElement instanceof NavigatorPage) {
82                      return filters.toArray();
83                  }
84                  return super.getElements(inputElement);
85              }
86          });
87          viewer.setLabelProvider(new LabelProvider());
88          viewer.setInput(this);
89          
90          viewer.setCheckedElements(calcActiveFilters());
91          viewer.addCheckStateListener(new ICheckStateListener() {
92              public void checkStateChanged(CheckStateChangedEvent event) {
93                  dirty = true;
94              }
95          });
96  
97          showAttrButton = new Button(mainHolder, SWT.CHECK);
98          showAttrButton.setText("Show concept attributes in tree");
99          showAttrButton.setImage(JFaceResources.getImage(WsmoImageRegistry.ATTRIBUTE_ICON));
100         showAttrButton.setSelection(isShowingAttrs());
101         showAttrButton.addSelectionListener(new SelectionAdapter() {
102             public void widgetSelected(SelectionEvent event) {
103                 dirty = true;
104             }
105         });
106         
107         return mainHolder;
108     }
109     
110     
111     public void init(IWorkbench workbench) {
112     }
113     
114     public boolean performOk() {
115         WsmoUIPlugin.getDefault().getPreferenceStore().setValue(HIDE_ATTRS_IN_TREE, 
116                 showAttrButton.getSelection() == false);
117         updateActiveFilters();
118         return super.performOk();
119     }
120     
121     protected void performDefaults() {
122         viewer.setAllChecked(true);
123         showAttrButton.setSelection(true);
124         super.performDefaults();
125     }
126     
127     public static boolean isShowingAttrs() {
128         return false == WsmoUIPlugin.getDefault().getPreferenceStore()
129                 .getBoolean(HIDE_ATTRS_IN_TREE);
130     }
131     
132     public void dispose() {
133         viewer = null;
134         filters = null;
135     }
136     
137     private Object[] calcActiveFilters() {
138         List<Object> buffer = new LinkedList<Object>();
139         for(ContentExtensionManager.FilterConfigWrapper filter : filters) {
140             if (false == getPreferenceStore().getBoolean(
141                     ContentExtensionManager.ACTIVE_FILTERS_PROPERTY_PREFIX 
142                     + filter.name)) {
143                 buffer.add(filter);
144             }
145 
146         }
147         return buffer.toArray();
148     }
149     
150     private void updateActiveFilters() {
151         if (dirty == false) {
152             return; // no need to update
153         }
154         for (ContentExtensionManager.FilterConfigWrapper filter : filters) {
155             getPreferenceStore().setValue(
156                     ContentExtensionManager.ACTIVE_FILTERS_PROPERTY_PREFIX 
157                     + filter.name,
158                     false == viewer.getChecked(filter));
159         }
160         
161         IWorkbenchPage page = PlatformUI.getWorkbench()
162                                   .getActiveWorkbenchWindow()
163                                       .getActivePage();
164         if (page == null) {
165             return;
166         }
167         WSMONavigator naviView = (WSMONavigator)page.findView(
168                                                     "org.wsmostudio.ui.views.WSMOView");
169         if (naviView != null) {
170             naviView.notifyActiveFiltersChange();
171         }
172     }
173 
174 }
175 
176 /*
177  * $Log$
178  * Revision 1.3  2007/03/13 17:49:30  alex_simov
179  * Visualization of concept attributes in WSMO Navigator is optional
180  *
181  * Revision 1.2  2006/01/09 12:51:13  alex_simov
182  * Copyright message in header updated
183  *
184  * Revision 1.1  2005/10/14 13:25:18  alex_simov
185  * WSMO Navigator's extension point creation
186  *
187  *
188  */