1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Google, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.internal.core.model.property.editor;
import org.eclipse.swt.graphics.GC;
import org.eclipse.wb.internal.core.model.property.Property;
import org.eclipse.wb.internal.core.model.property.table.PropertyTable;
import org.eclipse.wb.internal.core.model.property.table.PropertyTooltipProvider;
import org.eclipse.wb.internal.core.utils.ui.DrawUtils;
/**
* Abstract {@link PropertyEditor} for displaying text as {@link Property} value in
* {@link PropertyTable}.
*
* @author scheglov_ke
* @coverage core.model.property.editor
*/
public abstract class TextDisplayPropertyEditor extends PropertyEditor {
////////////////////////////////////////////////////////////////////////////
//
// Presentation
//
////////////////////////////////////////////////////////////////////////////
@Override
public void paint(Property property, GC gc, int x, int y, int width, int height) throws Exception {
String text = getText(property);
if (text != null) {
DrawUtils.drawStringCV(gc, text, x, y, width, height);
}
}
/**
* @return the text for displaying value of given {@link Property} or <code>null</code> if value
* of {@link Property} is unknown.
*/
protected abstract String getText(Property property) throws Exception;
////////////////////////////////////////////////////////////////////////////
//
// IAdaptable
//
////////////////////////////////////////////////////////////////////////////
@Override
public <T> T getAdapter(Class<T> adapter) {
// tooltip for value text
if (adapter == PropertyTooltipProvider.class) {
return adapter.cast(createPropertyTooltipProvider());
}
return super.getAdapter(adapter);
}
/**
* @return the {@link PropertyTooltipProvider} to display value tooltip.
*/
protected PropertyTooltipProvider createPropertyTooltipProvider() {
return null;
}
}
|