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.HashMap;
28  import java.util.Iterator;
29  import java.util.LinkedList;
30  import java.util.Map;
31  import java.util.Set;
32  
33  import org.eclipse.jface.preference.PreferencePage;
34  import org.eclipse.swt.events.*;
35  import org.eclipse.swt.layout.*;
36  import org.eclipse.swt.widgets.*;
37  import org.eclipse.swt.SWT;
38  import org.eclipse.ui.*;
39  import org.wsmostudio.ui.WsmoUIPlugin;
40  import org.wsmostudio.ui.editors.extension.ExtensionManager;
41  
42  /***
43   * A preference page which determines the preferred editors for certain WSMO entities.
44   * Such determination is important when there exist more than one editor registered 
45   * for a certain type of objects.
46   *
47   * @author not attributable
48   * @version $Revision: 618 $ $Date: 2006-03-06 16:37:44 +0200 $
49   */
50  
51  public class PreferredEditorsPage extends PreferencePage 
52  implements IWorkbenchPreferencePage {
53  
54      
55      private Set<String> allClasses;
56      private Map<String, String> classes2editors;
57      
58      @SuppressWarnings("unchecked")
59      protected Control createContents(Composite parent) {
60          final Group mainPanel = new Group(parent, SWT.V_SCROLL | SWT.H_SCROLL);
61          mainPanel.setText("Preferred Editors");
62          mainPanel.setLayout(new GridLayout(2, true));
63          
64          ExtensionManager manager = WsmoUIPlugin.getDefault().getExtensionManager();
65          allClasses = manager.getDefinedClasses();
66          classes2editors = new HashMap<String, String>();
67          
68          for(Iterator it = allClasses.iterator(); it.hasNext();) {
69              final String entry = (String)it.next();
70              LinkedList<String> editors = manager.getRegisteredEditors(entry);
71              if (editors.size() == 0) {
72                  continue;
73              }
74              String preferredEditor = manager.findPreferredEditor(entry);
75              if (preferredEditor == null
76                      || editors.indexOf(preferredEditor) == -1) {
77                  preferredEditor = editors.getFirst();
78              }
79              int prefIndex = editors.indexOf(preferredEditor);
80              classes2editors.put(entry, preferredEditor);
81              
82              Label lab = new Label(mainPanel, SWT.NONE);
83              lab.setText(entry);
84              lab.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE));
85  
86              final Combo editorsCombo = new Combo(mainPanel, SWT.DROP_DOWN | SWT.READ_ONLY);
87              editorsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
88              for(Iterator edIter = editors.iterator(); edIter.hasNext();) {
89                  String edID = (String)edIter.next();
90                  editorsCombo.add(manager.getEditorDescription(edID));
91              }
92              editorsCombo.select(prefIndex);
93              editorsCombo.setData(editors);
94              editorsCombo.addSelectionListener(new SelectionAdapter() {
95                  public void widgetSelected(SelectionEvent e) {
96                      LinkedList<String> localEditors = (LinkedList)editorsCombo.getData();
97                      classes2editors.put(entry, localEditors.get(editorsCombo.getSelectionIndex()));
98                  }
99              });
100         }
101         return mainPanel;
102     }
103     
104     public void init(IWorkbench workbench) {
105     }
106     
107 	protected void performDefaults() {
108 	}
109     
110 	public boolean performOk() {
111 	    updateContent();
112 		return super.performOk();
113 	}
114     
115     public void updateContent() {
116         ExtensionManager manager = WsmoUIPlugin.getDefault().getExtensionManager();
117         for (String key : classes2editors.keySet()) {
118             manager.setPreferredEditor(key, classes2editors.get(key));
119         }
120     }
121 }
122 
123 /*
124  * $Log$
125  * Revision 1.6  2006/03/06 14:37:22  alex_simov
126  * Editors extension registry now works with string class names instead of
127  *  classes (thus coping with eclipse different classloaders)
128  *
129  * Revision 1.5  2006/01/09 12:51:13  alex_simov
130  * Copyright message in header updated
131  *
132  * Revision 1.4  2005/09/08 16:46:25  alex_simov
133  * Migrating to Java 1.5
134  *
135  * Revision 1.3  2005/08/02 10:33:20  alex_simov
136  * minor code and/or javadoc fixes
137  *
138  * Revision 1.2  2005/07/22 14:07:22  alex_simov
139  * added javadoc: class description, footer
140  *
141  */