KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > visualcontent > ui > preferences > NodeTreePreferencePage


1 /**
2  * VC Browser - Visualizes the content of a JSR 170 compatible repository
3  * Copyright (C) 2006 Sandro Böhme
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.visualcontent.ui.preferences;
19
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.eclipse.core.runtime.IConfigurationElement;
24 import org.eclipse.core.runtime.IExtensionRegistry;
25 import org.eclipse.core.runtime.Platform;
26 import org.eclipse.jface.preference.FieldEditorPreferencePage;
27 import org.eclipse.jface.preference.RadioGroupFieldEditor;
28 import org.eclipse.ui.IWorkbench;
29 import org.eclipse.ui.IWorkbenchPreferencePage;
30 import org.visualcontent.extensionpoints.VCRepository;
31 import org.visualcontent.ui.UiPlugin;
32
33 public class NodeTreePreferencePage
34     extends FieldEditorPreferencePage
35     implements IWorkbenchPreferencePage {
36
37     private Map JavaDoc sessionIdSessionMap = new HashMap JavaDoc();
38     private Map JavaDoc sessionIdNameMap = new HashMap JavaDoc();
39     private String JavaDoc[][] repositoryChoice = null;
40     public NodeTreePreferencePage() {
41         
42         super(GRID);
43         setPreferenceStore(UiPlugin.getDefault().getPreferenceStore());
44         setDescription("Version: "+UiPlugin.getDefault().getBundle().getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION));
45     }
46     
47     /**
48      * Creates the field editors. Field editors are abstractions of
49      * the common GUI blocks needed to manipulate various types
50      * of preferences. Each field editor knows how to save and
51      * restore itself.
52      */

53     public void createFieldEditors() {
54         if (this.repositoryChoice.length>1){
55             addField(new RadioGroupFieldEditor(
56                     PreferenceConstants.P_REPOSITORY_CHOICE,
57                 "Please choose the repository connector to use.",
58                 1,
59                 this.repositoryChoice, getFieldEditorParent()));
60         }
61     }
62
63     /* (non-Javadoc)
64      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
65      */

66     public void init(IWorkbench workbench) {
67         IExtensionRegistry registry = Platform.getExtensionRegistry ();
68         IConfigurationElement[] repositoryConfigElements = registry.getConfigurationElementsFor("org.visualcontent.extensionpoints.VCRepository");
69         this.repositoryChoice = new String JavaDoc[repositoryConfigElements.length][2];
70         for (int i = 0; i < repositoryConfigElements.length; i++) {
71             VCRepository repository = null;
72             this.repositoryChoice[i][0]=repositoryConfigElements[i].getAttribute("name");
73             this.repositoryChoice[i][1]=repositoryConfigElements[i].getAttribute("id");
74         }
75     }
76     public static String JavaDoc getDefaultRepositoryId(){
77         String JavaDoc defaultRepositoryId="";
78         IExtensionRegistry registry = Platform.getExtensionRegistry ();
79         IConfigurationElement[] repositoryConfigElements = registry.getConfigurationElementsFor("org.visualcontent.extensionpoints.VCRepository");
80         if (repositoryConfigElements.length<1){
81             String JavaDoc errorMessage="Please install a Repository connector plugin for the JCR Browser.";
82             UiPlugin.getDefault().showError(errorMessage,new RuntimeException JavaDoc(errorMessage));
83         } else {
84             defaultRepositoryId=repositoryConfigElements[0].getAttribute("id");
85             for (int i = 0; i < repositoryConfigElements.length; i++) {
86                 if ("org.visualcontent.authentication.jlibrarylistener".equals(repositoryConfigElements[i].getAttribute("id"))){
87                     defaultRepositoryId=repositoryConfigElements[i].getAttribute("id");
88                 }
89             }
90         }
91         return defaultRepositoryId;
92     }
93 }
Popular Tags