KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > feature > URLElementPropertySource


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.feature;
12
13 import java.net.*;
14 import java.util.*;
15
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.pde.internal.core.ifeature.*;
18 import org.eclipse.pde.internal.ui.*;
19 import org.eclipse.ui.views.properties.*;
20
21 public class URLElementPropertySource extends FeaturePropertySource {
22     private Vector descriptors;
23     private final static String JavaDoc P_URL = "url"; //$NON-NLS-1$
24
public final static String JavaDoc KEY_TYPE = "FeatureEditor.URLProp.type"; //$NON-NLS-1$
25
public final static String JavaDoc KEY_SITE_TYPE = "FeatureEditor.URLProp.siteType"; //$NON-NLS-1$
26
public final static String JavaDoc KEY_LABEL = "FeatureEditor.URLProp.label"; //$NON-NLS-1$
27
public final static String JavaDoc KEY_URL = "FeatureEditor.URLProp.URL"; //$NON-NLS-1$
28
private final static String JavaDoc P_TYPE = "type"; //$NON-NLS-1$
29
private final static String JavaDoc P_LABEL = "label"; //$NON-NLS-1$
30
private final static String JavaDoc P_SITE_TYPE = "siteType"; //$NON-NLS-1$
31
private final static String JavaDoc[] elementTypes =
32         {
33             null,
34             PDEPlugin.getResourceString("FeatureEditor.URLProp.type.update"), //$NON-NLS-1$
35
PDEPlugin.getResourceString(
36                 "FeatureEditor.URLProp.type.discovery")}; //$NON-NLS-1$
37

38     private final static String JavaDoc[] siteTypes = { "update", "web" }; //$NON-NLS-1$ //$NON-NLS-2$
39

40     public URLElementPropertySource(IFeatureURLElement element) {
41         super(element);
42     }
43     public org
44
        .eclipse
45         .pde
46         .internal
47         .core
48         .ifeature
49         .IFeatureURLElement getElement() {
50         return (IFeatureURLElement) object;
51     }
52     public IPropertyDescriptor[] getPropertyDescriptors() {
53         if (descriptors == null) {
54             descriptors = new Vector();
55             PropertyDescriptor desc =
56                 new PropertyDescriptor(
57                     P_TYPE,
58                     PDEPlugin.getResourceString(KEY_TYPE));
59             descriptors.addElement(desc);
60             desc =
61                 createTextPropertyDescriptor(
62                     P_LABEL,
63                     PDEPlugin.getResourceString(KEY_LABEL));
64             descriptors.addElement(desc);
65             desc =
66                 createTextPropertyDescriptor(
67                     P_URL,
68                     PDEPlugin.getResourceString(KEY_URL));
69             descriptors.addElement(desc);
70             desc =
71                 createChoicePropertyDescriptor(
72                     P_SITE_TYPE,
73                     PDEPlugin.getResourceString(KEY_SITE_TYPE),
74                     siteTypes);
75             descriptors.addElement(desc);
76         }
77         return toDescriptorArray(descriptors);
78     }
79     public Object JavaDoc getPropertyValue(Object JavaDoc name) {
80         if (name.equals(P_TYPE)) {
81             return elementTypes[getElement().getElementType()];
82         }
83         if (name.equals(P_LABEL)) {
84             return getElement().getLabel();
85         }
86         if (name.equals(P_URL)) {
87             return getElement().getURL().toString();
88         }
89         if (name.equals(P_SITE_TYPE)) {
90             return new Integer JavaDoc(getElement().getSiteType());
91         }
92         return null;
93     }
94     public void setElement(IFeatureURLElement newElement) {
95         object = newElement;
96     }
97     public void setPropertyValue(Object JavaDoc name, Object JavaDoc value) {
98         String JavaDoc svalue = value.toString();
99         String JavaDoc realValue =
100             svalue == null | svalue.length() == 0 ? null : svalue;
101         try {
102             if (name.equals(P_URL)) {
103                 try {
104                     URL url = null;
105                     if (realValue != null)
106                         url = new URL(realValue);
107                     getElement().setURL(url);
108                 } catch (MalformedURLException e) {
109                 }
110             } else if (name.equals(P_LABEL)) {
111                 getElement().setLabel(realValue);
112             } else if (name.equals(P_SITE_TYPE)) {
113                 Integer JavaDoc ivalue = (Integer JavaDoc) value;
114                 getElement().setSiteType(ivalue.intValue());
115             }
116         } catch (CoreException e) {
117             PDEPlugin.logException(e);
118         }
119     }
120 }
121
Popular Tags