intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.js.ui / src / net / sourceforge / phpeclipse / js / ui / model / JSNameSorter.java
1 /*
2  * Copyright (c) 2003-2004 Alex Fitzpatrick 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  *     Alex Fitzpatrick - initial implementation
10  * 
11  * $Id: JSNameSorter.java,v 1.1 2004-09-02 18:23:57 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.js.ui.model;
15
16 import net.sourceforge.phpeclipse.js.core.model.JSClassElement;
17 import net.sourceforge.phpeclipse.js.core.model.JSClassMethodElement;
18 import net.sourceforge.phpeclipse.js.core.model.JSClassVariableElement;
19 import net.sourceforge.phpeclipse.js.core.model.JSFunctionElement;
20 import net.sourceforge.phpeclipse.js.core.model.JSGlobalVariableElement;
21 import net.sourceforge.phpeclipse.js.core.model.JSInstanceMethodElement;
22 import net.sourceforge.phpeclipse.js.core.model.JSInstanceVariableElement;
23
24 import org.eclipse.jface.viewers.ViewerSorter;
25
26 /**
27  * Name sorter.
28  */
29 public class JSNameSorter extends ViewerSorter {
30
31         // ViewerSorter Implementation ---------------------------------------------
32
33         /*
34          * @see ViewerSorter#category(Object)
35          */
36         public int category(Object element) {
37                 if (element instanceof JSClassElement) {
38                         return JSElementCategories.CLASS;
39                 } else if (element instanceof JSFunctionElement) {
40                         return JSElementCategories.FUNCTION;
41                 } else if (element instanceof JSGlobalVariableElement) {
42                         return JSElementCategories.VARIABLE;
43                 } else if (element instanceof JSClassVariableElement) {
44                         return JSElementCategories.CLASS_VARIABLE;
45                 } else if (element instanceof JSInstanceVariableElement) {
46                         return JSElementCategories.INSTANCE_VARIABLE;
47                 } else if (element instanceof JSClassMethodElement) {
48                         return JSElementCategories.CLASS_METHOD;
49                 } else if (element instanceof JSInstanceMethodElement) {
50                         return JSElementCategories.INSTANCE_VARIABLE;
51                 }
52                 return super.category(element);
53         }
54
55 }