Trim code
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 26 Sep 2016 04:32:13 +0000 (06:32 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 26 Sep 2016 04:32:13 +0000 (06:32 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermLabelProvider.java

index da2a355239fc8f1ce645c64d134f996d65e8db6c..71e33bed7c19c9a133e281413a08e10b76955717 100644 (file)
-// $Id$\r
-/**\r
- * Copyright (C) 2009 EDIT\r
- * European Distributed Institute of Taxonomy\r
- * http://www.e-taxonomy.eu\r
- *\r
- * The contents of this file are subject to the Mozilla Public License Version 1.1\r
- * See LICENSE.TXT at the top of this package for the full license terms.\r
- */\r
-package eu.etaxonomy.taxeditor.editor.definedterm;\r
-\r
-import java.util.ArrayList;\r
-\r
-import org.apache.commons.lang.StringUtils;\r
-import org.eclipse.jface.viewers.StyledCellLabelProvider;\r
-import org.eclipse.jface.viewers.StyledString;\r
-import org.eclipse.jface.viewers.StyledString.Styler;\r
-import org.eclipse.jface.viewers.ViewerCell;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.StyleRange;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.TextStyle;\r
-import org.eclipse.swt.widgets.Display;\r
-\r
-import eu.etaxonomy.cdm.common.CdmUtils;\r
-import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
-import eu.etaxonomy.cdm.model.common.Language;\r
-import eu.etaxonomy.cdm.model.common.Representation;\r
-import eu.etaxonomy.cdm.model.common.TermBase;\r
-import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;\r
-\r
-/**\r
- * @author l.morris\r
- * @date 9 Dec 2011\r
- *\r
- */\r
-public class TermLabelProvider extends StyledCellLabelProvider {\r
-\r
-    private static Color vocColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);\r
-    private Styler vocStyler;\r
-\r
-    public TermLabelProvider() {\r
-    }\r
-\r
-    public TermLabelProvider(Styler vocStyler){\r
-        this.vocStyler = vocStyler;\r
-    }\r
-\r
-    /*\r
-     * (non-Javadoc)\r
-     *\r
-     * @see\r
-     * org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.\r
-     * jface.viewers.ViewerCell)\r
-     */\r
-    @Override\r
-    public void update(ViewerCell cell) {\r
-        Object element = cell.getElement();\r
-        int columnIndex = cell.getColumnIndex();\r
-\r
-        String text = getText(element);\r
-        cell.setText(text);\r
-\r
-        if (element instanceof TermVocabulary) {\r
-            StyledString styledString = new StyledString(text, getVocabularyStyler());\r
-            StyleRange[] styleRanges;\r
-            styleRanges = styledString.getStyleRanges();\r
-            cell.setStyleRanges(styleRanges);\r
-        }\r
-        super.update(cell);\r
-    }\r
-\r
-    public StyledString getStyledText(Object element) {\r
-\r
-        if (element instanceof TermVocabulary) {\r
-            new StyledString(getText(element), getVocabularyStyler());\r
-        }\r
-        return new StyledString(getText(element), StyledString.QUALIFIER_STYLER);\r
-    }\r
-\r
-    public String getText(Object element) {\r
-\r
-        if (element instanceof DefinedTermBase) {\r
-            DefinedTermBase<?> dtb = (DefinedTermBase<?>) element;\r
-\r
-            Representation rep = dtb.getRepresentation(PreferencesUtil.getGlobalLanguage());\r
-            if ( rep == null){\r
-                rep = dtb.getPreferredRepresentation(new ArrayList<Language>());\r
-            }\r
-            String label = rep != null? rep.getLabel() : dtb.getTitleCache();\r
-            return CdmUtils.concat(" : ", dtb.getIdInVocabulary(), label);\r
-\r
-        } else if (element instanceof TermBase) {\r
-            return ((TermBase) element).getTitleCache();\r
-        }\r
-\r
-        // FIXME : must throw an exception here\r
-        return element.toString();\r
-    }\r
-\r
-    private Styler getVocabularyStyler() {\r
-        if (vocStyler == null) {\r
-            vocStyler = new Styler() {\r
-                @Override\r
-                public void applyStyles(TextStyle textStyle) {\r
-                    textStyle.foreground = vocColor;\r
-                }\r
-            };\r
-        }\r
-        return vocStyler;\r
-    }\r
-\r
-}\r
+// $Id$
+/**
+ * Copyright (C) 2009 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
+package eu.etaxonomy.taxeditor.editor.definedterm;
+
+import java.util.ArrayList;
+
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.StyledString.Styler;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.TextStyle;
+import org.eclipse.swt.widgets.Display;
+
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.Representation;
+import eu.etaxonomy.cdm.model.common.TermBase;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+
+/**
+ * @author l.morris
+ * @date 9 Dec 2011
+ *
+ */
+public class TermLabelProvider extends StyledCellLabelProvider {
+
+    private static Color vocColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
+    private Styler vocStyler;
+
+    public TermLabelProvider() {
+    }
+
+    public TermLabelProvider(Styler vocStyler){
+        this.vocStyler = vocStyler;
+    }
+
+    @Override
+    public void update(ViewerCell cell) {
+        Object element = cell.getElement();
+        int columnIndex = cell.getColumnIndex();
+
+        String text = getText(element);
+        cell.setText(text);
+
+        if (element instanceof TermVocabulary) {
+            StyledString styledString = new StyledString(text, getVocabularyStyler());
+            StyleRange[] styleRanges;
+            styleRanges = styledString.getStyleRanges();
+            cell.setStyleRanges(styleRanges);
+        }
+        super.update(cell);
+    }
+
+    public StyledString getStyledText(Object element) {
+
+        if (element instanceof TermVocabulary) {
+            new StyledString(getText(element), getVocabularyStyler());
+        }
+        return new StyledString(getText(element), StyledString.QUALIFIER_STYLER);
+    }
+
+    public String getText(Object element) {
+
+        if (element instanceof DefinedTermBase) {
+            DefinedTermBase<?> dtb = (DefinedTermBase<?>) element;
+
+            Representation rep = dtb.getRepresentation(PreferencesUtil.getGlobalLanguage());
+            if ( rep == null){
+                rep = dtb.getPreferredRepresentation(new ArrayList<Language>());
+            }
+            String label = rep != null? rep.getLabel() : dtb.getTitleCache();
+            return CdmUtils.concat(" : ", dtb.getIdInVocabulary(), label);
+
+        } else if (element instanceof TermBase) {
+            return ((TermBase) element).getTitleCache();
+        }
+
+        // FIXME : must throw an exception here
+        return element.toString();
+    }
+
+    private Styler getVocabularyStyler() {
+        if (vocStyler == null) {
+            vocStyler = new Styler() {
+                @Override
+                public void applyStyles(TextStyle textStyle) {
+                    textStyle.foreground = vocColor;
+                }
+            };
+        }
+        return vocStyler;
+    }
+
+}