2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.eclipse.org/org/documents/epl-v10.php
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.
17 package com.android.ide.eclipse.adt.internal.editors.layout.gle2;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.graphics.Point;
21 import org.eclipse.swt.graphics.Rectangle;
22 import org.eclipse.swt.layout.FillLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Display;
25 import org.eclipse.swt.widgets.Event;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.Listener;
28 import org.eclipse.swt.widgets.Shell;
29 import org.eclipse.swt.widgets.Tree;
30 import org.eclipse.swt.widgets.TreeItem;
31 import org.eclipse.ui.views.properties.PropertySheetEntry;
32 import org.eclipse.ui.views.properties.PropertySheetPage;
35 * A customized property sheet page for the graphical layout editor v2.
37 * Currently it just provides a custom tooltip to display attributes javadocs.
39 * The property sheet is linked to the current site's selection service.
41 * Note: this is an exact copy of GLE1's UiPropertySheetPage implementation.
42 * The idea is that eventually GLE1 will go away and we'll upgrade this to be
43 * a more robust property editor (it currently lacks on so many levels, it's not
44 * even worth listing the flaws.)
48 public class PropertySheetPage2 extends PropertySheetPage {
51 public PropertySheetPage2() {
56 public void createControl(Composite parent) {
57 super.createControl(parent);
63 * Sets up a custom tooltip when hovering over tree items.
65 * The tooltip will display the element's javadoc, if any, or the item's getText otherwise.
67 private void setupTooltip() {
68 final Tree tree = (Tree) getControl();
72 * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java?view=markup
75 final Listener listener = new Listener() {
79 public void handleEvent(Event event) {
99 String tooltip = null;
101 TreeItem item = tree.getItem(new Point(event.x, event.y));
103 Object data = item.getData();
104 if (data instanceof PropertySheetEntry) {
105 tooltip = ((PropertySheetEntry) data).getDescription();
108 if (tooltip == null) {
109 tooltip = item.getText();
111 tooltip = item.getText() + ":\r" + tooltip;
114 if (tooltip != null) {
115 Shell shell = tree.getShell();
116 Display display = tree.getDisplay();
118 tip = new Shell(shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
119 tip.setBackground(display .getSystemColor(SWT.COLOR_INFO_BACKGROUND));
120 FillLayout layout = new FillLayout();
121 layout.marginWidth = 2;
122 tip.setLayout(layout);
123 label = new Label(tip, SWT.NONE);
124 label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
125 label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
126 label.setData("_TABLEITEM", item);
127 label.setText(tooltip);
128 label.addListener(SWT.MouseExit, this);
129 label.addListener(SWT.MouseDown, this);
130 Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
131 Rectangle rect = item.getBounds(0);
132 Point pt = tree.toDisplay(rect.x, rect.y);
133 tip.setBounds(pt.x, pt.y, size.x, size.y);
134 tip.setVisible(true);
141 tree.addListener(SWT.Dispose, listener);
142 tree.addListener(SWT.KeyDown, listener);
143 tree.addListener(SWT.MouseMove, listener);
144 tree.addListener(SWT.MouseHover, listener);