1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.ide.eclipse.adt.internal.editors.layout.gle2; 17 18 import static com.android.SdkConstants.ATTR_ID; 19 20 import com.android.ide.common.layout.BaseLayoutRule; 21 import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate; 22 import com.android.ide.eclipse.adt.internal.editors.layout.uimodel.UiViewElementNode; 23 24 import org.eclipse.core.resources.IMarker; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.graphics.Color; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.layout.GridLayout; 29 import org.eclipse.swt.widgets.Display; 30 import org.eclipse.swt.widgets.Label; 31 import org.eclipse.swt.widgets.Shell; 32 33 import java.util.List; 34 35 /** Actual tooltip showing multiple lines for various widgets that have lint errors */ 36 class LintTooltip extends Shell { 37 private final LayoutCanvas mCanvas; 38 private final List<UiViewElementNode> mNodes; 39 40 LintTooltip(LayoutCanvas canvas, List<UiViewElementNode> nodes) { 41 super(canvas.getDisplay(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); 42 mCanvas = canvas; 43 mNodes = nodes; 44 45 createContents(); 46 } 47 48 protected void createContents() { 49 Display display = getDisplay(); 50 Color fg = display.getSystemColor(SWT.COLOR_INFO_FOREGROUND); 51 Color bg = display.getSystemColor(SWT.COLOR_INFO_BACKGROUND); 52 setBackground(bg); 53 GridLayout gridLayout = new GridLayout(2, false); 54 setLayout(gridLayout); 55 56 LayoutEditorDelegate delegate = mCanvas.getEditorDelegate(); 57 58 boolean first = true; 59 for (UiViewElementNode node : mNodes) { 60 IMarker marker = delegate.getIssueForNode(node); 61 if (marker != null) { 62 String message = marker.getAttribute(IMarker.MESSAGE, null); 63 if (message != null) { 64 Label icon = new Label(this, SWT.NONE); 65 icon.setForeground(fg); 66 icon.setBackground(bg); 67 icon.setImage(node.getIcon()); 68 69 Label label = new Label(this, SWT.WRAP); 70 if (first) { 71 label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); 72 first = false; 73 } 74 75 String id = BaseLayoutRule.stripIdPrefix(node.getAttributeValue(ATTR_ID)); 76 if (id.isEmpty()) { 77 if (node.getXmlNode() != null) { 78 id = node.getXmlNode().getNodeName(); 79 } else { 80 id = node.getDescriptor().getUiName(); 81 } 82 } 83 84 label.setText(String.format("%1$s: %2$s", id, message)); 85 } 86 } 87 } 88 } 89 90 @Override 91 protected void checkSubclass() { 92 // Disable the check that prevents subclassing of SWT components 93 } 94 } 95