diff options
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java')
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java new file mode 100644 index 0000000..ea3f066 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/OutlineLabelProvider.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.eclipse.org/org/documents/epl-v10.php + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.ide.eclipse.adt.internal.editors; + +import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; +import static com.android.ide.common.layout.LayoutConstants.ATTR_ID; +import static com.android.ide.common.layout.LayoutConstants.ATTR_NAME; +import static com.android.ide.common.layout.LayoutConstants.ATTR_SRC; +import static com.android.ide.common.layout.LayoutConstants.ATTR_TEXT; +import static com.android.ide.common.layout.LayoutConstants.DRAWABLE_PREFIX; +import static com.android.ide.common.layout.LayoutConstants.LAYOUT_PREFIX; + +import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDescriptors; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeLabelProvider; +import org.w3c.dom.Element; + +/** Label provider for the XML outlines and quick outlines: Use our own icons, + * when available, and and include the most important attribute (id, name, or text) */ +@SuppressWarnings("restriction") // XML UI API +class OutlineLabelProvider extends JFaceNodeLabelProvider { + @Override + public Image getImage(Object element) { + if (element instanceof Element) { + Element e = (Element) element; + String tagName = e.getTagName(); + IconFactory factory = IconFactory.getInstance(); + Image img = factory.getIcon(tagName, null); + if (img != null) { + return img; + } + } + return super.getImage(element); + } + + @Override + public String getText(Object element) { + String text = super.getText(element); + if (element instanceof Element) { + Element e = (Element) element; + String id = e.getAttributeNS(ANDROID_URI, ATTR_ID); + if (id == null || id.length() == 0) { + id = e.getAttributeNS(ANDROID_URI, ATTR_NAME); + if (id == null || id.length() == 0) { + id = e.getAttribute(ATTR_NAME); + if (id == null || id.length() == 0) { + id = e.getAttributeNS(ANDROID_URI, ATTR_TEXT); + if (id != null && id.length() > 15) { + id = id.substring(0, 12) + "..."; + } + if (id == null || id.length() == 0) { + id = e.getAttributeNS(ANDROID_URI, ATTR_SRC); + if (id != null && id.length() > 0) { + if (id.startsWith(DRAWABLE_PREFIX)) { + id = id.substring(DRAWABLE_PREFIX.length()); + } + } else { + id = e.getAttribute(LayoutDescriptors.ATTR_LAYOUT); + if (id != null && id.length() > 0) { + if (id.startsWith(LAYOUT_PREFIX)) { + id = id.substring(LAYOUT_PREFIX.length()); + } + } + } + } + } + } + } + + if (id != null && id.length() > 0) { + return text + ": " + id; //$NON-NLS-1$ + } + } + return text; + } +}
\ No newline at end of file |