KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > internal > ui > SorterDescriptor


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

11 package org.eclipse.search.internal.ui;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IConfigurationElement;
15 import org.eclipse.core.runtime.Path;
16 import org.eclipse.core.runtime.Platform;
17
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.jface.viewers.ViewerSorter;
20
21 import org.eclipse.search.internal.ui.util.ExceptionHandler;
22
23 import org.osgi.framework.Bundle;
24
25 /**
26  * Proxy that represents a sorter.
27  */

28 class SorterDescriptor {
29
30     public final static String JavaDoc SORTER_TAG= "sorter"; //$NON-NLS-1$
31
private final static String JavaDoc ID_ATTRIBUTE= "id"; //$NON-NLS-1$
32
private final static String JavaDoc PAGE_ID_ATTRIBUTE= "pageId"; //$NON-NLS-1$
33
private final static String JavaDoc ICON_ATTRIBUTE= "icon"; //$NON-NLS-1$
34
private final static String JavaDoc CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
35
private final static String JavaDoc LABEL_ATTRIBUTE= "label"; //$NON-NLS-1$
36
private final static String JavaDoc TOOLTIP_ATTRIBUTE= "tooltip"; //$NON-NLS-1$
37

38     private IConfigurationElement fElement;
39     
40     /**
41      * Creates a new sorter node with the given configuration element.
42      *
43      * @param element the configuration element
44      */

45     public SorterDescriptor(IConfigurationElement element) {
46         fElement= element;
47     }
48
49     /**
50      * Creates a new sorter from this node.
51      */

52     public ViewerSorter createObject() {
53         try {
54             return (ViewerSorter)fElement.createExecutableExtension(CLASS_ATTRIBUTE);
55         } catch (CoreException ex) {
56             ExceptionHandler.handle(ex, SearchMessages.Search_Error_createSorter_title, SearchMessages.Search_Error_createSorter_message);
57             return null;
58         } catch (ClassCastException JavaDoc ex) {
59             ExceptionHandler.displayMessageDialog(ex, SearchMessages.Search_Error_createSorter_title, SearchMessages.Search_Error_createSorter_message);
60             return null;
61         }
62     }
63     
64     //---- XML Attribute accessors ---------------------------------------------
65

66     /**
67      * Returns the sorter's id.
68      */

69     public String JavaDoc getId() {
70         return fElement.getAttribute(ID_ATTRIBUTE);
71     }
72      
73     /**
74      * Returns the sorter's image
75      */

76     public ImageDescriptor getImage() {
77         String JavaDoc imageName= fElement.getAttribute(ICON_ATTRIBUTE);
78         if (imageName == null)
79             return null;
80         Bundle bundle = Platform.getBundle(fElement.getContributor().getName());
81         return SearchPluginImages.createImageDescriptor(bundle, new Path(imageName), true);
82     }
83
84     /**
85      * Returns the sorter's label.
86      */

87     public String JavaDoc getLabel() {
88         return fElement.getAttribute(LABEL_ATTRIBUTE);
89     }
90     
91     /**
92      * Returns the sorter's preferred size
93      */

94     public String JavaDoc getToolTipText() {
95         return fElement.getAttribute(TOOLTIP_ATTRIBUTE);
96     }
97
98     /**
99      * Returns the sorter's preferred size
100      */

101     public String JavaDoc getPageId() {
102         return fElement.getAttribute(PAGE_ID_ATTRIBUTE);
103     }
104 }
105
Popular Tags