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
diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSNameSorter.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/model/JSNameSorter.java
new file mode 100644 (file)
index 0000000..bc16e53
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2003-2004 Alex Fitzpatrick and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ * 
+ * Contributors:
+ *     Alex Fitzpatrick - initial implementation
+ * 
+ * $Id: JSNameSorter.java,v 1.1 2004-09-02 18:23:57 jsurfer Exp $
+ */
+
+package net.sourceforge.phpeclipse.js.ui.model;
+
+import net.sourceforge.phpeclipse.js.core.model.JSClassElement;
+import net.sourceforge.phpeclipse.js.core.model.JSClassMethodElement;
+import net.sourceforge.phpeclipse.js.core.model.JSClassVariableElement;
+import net.sourceforge.phpeclipse.js.core.model.JSFunctionElement;
+import net.sourceforge.phpeclipse.js.core.model.JSGlobalVariableElement;
+import net.sourceforge.phpeclipse.js.core.model.JSInstanceMethodElement;
+import net.sourceforge.phpeclipse.js.core.model.JSInstanceVariableElement;
+
+import org.eclipse.jface.viewers.ViewerSorter;
+
+/**
+ * Name sorter.
+ */
+public class JSNameSorter extends ViewerSorter {
+
+       // ViewerSorter Implementation ---------------------------------------------
+
+       /*
+        * @see ViewerSorter#category(Object)
+        */
+       public int category(Object element) {
+               if (element instanceof JSClassElement) {
+                       return JSElementCategories.CLASS;
+               } else if (element instanceof JSFunctionElement) {
+                       return JSElementCategories.FUNCTION;
+               } else if (element instanceof JSGlobalVariableElement) {
+                       return JSElementCategories.VARIABLE;
+               } else if (element instanceof JSClassVariableElement) {
+                       return JSElementCategories.CLASS_VARIABLE;
+               } else if (element instanceof JSInstanceVariableElement) {
+                       return JSElementCategories.INSTANCE_VARIABLE;
+               } else if (element instanceof JSClassMethodElement) {
+                       return JSElementCategories.CLASS_METHOD;
+               } else if (element instanceof JSInstanceMethodElement) {
+                       return JSElementCategories.INSTANCE_VARIABLE;
+               }
+               return super.category(element);
+       }
+
+}