|
Lines 1-126
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008 Innoopract Informationssysteme GmbH. |
2 |
* Copyright (c) 2008 Innoopract Informationssysteme GmbH. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* Innoopract Informationssysteme GmbH - initial API and implementation |
9 |
* Innoopract Informationssysteme GmbH - initial API and implementation |
| 10 |
******************************************************************************/ |
10 |
******************************************************************************/ |
| 11 |
|
11 |
|
| 12 |
qx.Class.define( "org.eclipse.swt.widgets.ExpandItem", { |
12 |
qx.Class.define( "org.eclipse.swt.widgets.ExpandItem", { |
| 13 |
extend : qx.ui.layout.CanvasLayout, |
13 |
extend : qx.ui.layout.CanvasLayout, |
| 14 |
|
14 |
|
| 15 |
construct : function( parent ) { |
15 |
construct : function( parent ) { |
| 16 |
this.base( arguments ); |
16 |
this.base( arguments ); |
| 17 |
if( parent.classname != "org.eclipse.swt.widgets.ExpandBar" ) { |
17 |
if( parent.classname != "org.eclipse.swt.widgets.ExpandBar" ) { |
| 18 |
this.error( "illegal parent, must be a ExpandBar" ); |
18 |
this.error( "illegal parent, must be a ExpandBar" ); |
| 19 |
} |
19 |
} |
| 20 |
this.setAppearance( "expand-item" ); |
20 |
this.setAppearance( "expand-item" ); |
| 21 |
this._expandBar = parent; |
21 |
this._expandBar = parent; |
| 22 |
this._headerHeight = 24; // Chevron size with top/bottom insets |
22 |
this._headerHeight = 24; // Chevron size with top/bottom insets |
| 23 |
this._expanded = false; |
23 |
this._expanded = false; |
| 24 |
this._image = null; |
24 |
this._image = null; |
| 25 |
this._text = ""; |
25 |
this._text = ""; |
| 26 |
// Construct a header area |
26 |
// Construct a header area |
| 27 |
this._header = new qx.ui.basic.Atom( "(empty)", this._image, 16, 16 ); |
27 |
this._header = new qx.ui.basic.Atom( "(empty)", this._image, 16, 16 ); |
| 28 |
this._header.getLabelObject().setPaddingBottom( 4 ); |
28 |
this._header.getLabelObject().setPaddingBottom( 4 ); |
| 29 |
this._header.setAppearance( "expand-item-header" ); |
29 |
this._header.setAppearance( "expand-item-header" ); |
| 30 |
this._header.addEventListener( "click", this._onClick, this ); |
30 |
this._header.addEventListener( "click", this._onClick, this ); |
| 31 |
this._header.addEventListener( "mouseover", this._onHandleMouseOver, this ); |
31 |
this._header.addEventListener( "mouseover", this._onHandleMouseOver, this ); |
| 32 |
this._header.addEventListener( "mouseout", this._onHandleMouseOut, this ); |
32 |
this._header.addEventListener( "mouseout", this._onHandleMouseOut, this ); |
| 33 |
this._header.addEventListener( "contextmenu", this._onContextMenu, this ); |
33 |
this._header.addEventListener( "contextmenu", this._onContextMenu, this ); |
| 34 |
this._header.setHeight( this._headerHeight ); |
34 |
this._header.setHeight( this._headerHeight ); |
| 35 |
this._header.setLabel( this._text ); |
35 |
this._header.setLabel( this._text ); |
| 36 |
this.add( this._header ); |
36 |
this.add( this._header ); |
| 37 |
// Chevron image |
37 |
// Chevron image |
| 38 |
this._chevron = new qx.ui.basic.Atom(); |
38 |
this._chevron = new qx.ui.basic.Atom(); |
| 39 |
this._chevron.setAppearance( "expand-item-chevron-button" ); |
39 |
this._chevron.setAppearance( "expand-item-chevron-button" ); |
| 40 |
this._chevron.setTop( ( this._headerHeight - this._chevron.getHeight() ) / 2 ); |
40 |
this._chevron.setTop( ( this._headerHeight - this._chevron.getHeight() ) / 2 ); |
| 41 |
this._chevron.addEventListener( "click", this._onClick, this ); |
41 |
this._chevron.addEventListener( "click", this._onClick, this ); |
| 42 |
this._chevron.addEventListener( "mouseover", this._onHandleMouseOver, this ); |
42 |
this._chevron.addEventListener( "mouseover", this._onHandleMouseOver, this ); |
| 43 |
this._chevron.addEventListener( "mouseout", this._onHandleMouseOut, this ); |
43 |
this._chevron.addEventListener( "mouseout", this._onHandleMouseOut, this ); |
| 44 |
this._chevron.addEventListener( "contextmenu", this._onContextMenu, this ); |
44 |
this._chevron.addEventListener( "contextmenu", this._onContextMenu, this ); |
| 45 |
this.add( this._chevron ); |
45 |
this.add( this._chevron ); |
| 46 |
this._frameBorder = new qx.ui.core.Border( 1, "solid" ); |
46 |
this._frameBorder = new qx.ui.core.Border( 1, "solid" ); |
| 47 |
this._frameBorder.setColor( this._header.getBackgroundColor() ); |
47 |
this._frameBorder.setColor( this._header.getBackgroundColor() ); |
| 48 |
this.setBorder( this._frameBorder ); |
48 |
this.setBorder( this._frameBorder ); |
| 49 |
}, |
49 |
}, |
| 50 |
|
50 |
|
| 51 |
destruct : function() { |
51 |
destruct : function() { |
| 52 |
this._header.removeEventListener( "click", this._onClick, this ); |
52 |
this._header.removeEventListener( "click", this._onClick, this ); |
| 53 |
this._header.removeEventListener( "mouseover", this._onHandleMouseOver, this ); |
53 |
this._header.removeEventListener( "mouseover", this._onHandleMouseOver, this ); |
| 54 |
this._header.removeEventListener( "mouseout", this._onHandleMouseOut, this ); |
54 |
this._header.removeEventListener( "mouseout", this._onHandleMouseOut, this ); |
| 55 |
this._header.removeEventListener( "contextmenu", this._onContextMenu, this ); |
55 |
this._header.removeEventListener( "contextmenu", this._onContextMenu, this ); |
| 56 |
this._chevron.removeEventListener( "click", this._onClick, this ); |
56 |
this._chevron.removeEventListener( "click", this._onClick, this ); |
| 57 |
this._chevron.removeEventListener( "mouseover", this._onHandleMouseOver, this ); |
57 |
this._chevron.removeEventListener( "mouseover", this._onHandleMouseOver, this ); |
| 58 |
this._chevron.removeEventListener( "mouseout", this._onHandleMouseOut, this ); |
58 |
this._chevron.removeEventListener( "mouseout", this._onHandleMouseOut, this ); |
| 59 |
this._chevron.removeEventListener( "contextmenu", this._onContextMenu, this ); |
59 |
this._chevron.removeEventListener( "contextmenu", this._onContextMenu, this ); |
| 60 |
this._disposeObjects( "_header", "_chevron", "_frameBorder" ); |
60 |
// this._disposeObjects( "_header", "_chevron", "_frameBorder" ); |
| 61 |
}, |
61 |
this._disposeObjects( "_frameBorder" ); |
| 62 |
|
62 |
this._header.destroy(); |
| 63 |
statics : { |
63 |
this._chevron.destroy(); |
| 64 |
STATE_EXPANDED : "expanded", |
64 |
}, |
| 65 |
STATE_OVER : "over" |
65 |
|
| 66 |
}, |
66 |
statics : { |
| 67 |
|
67 |
STATE_EXPANDED : "expanded", |
| 68 |
members : { |
68 |
STATE_OVER : "over" |
| 69 |
setExpanded : function( expanded ) { |
69 |
}, |
| 70 |
this._expanded = expanded; |
70 |
|
| 71 |
if( expanded ) { |
71 |
members : { |
| 72 |
this._chevron.addState( org.eclipse.swt.widgets.ExpandItem.STATE_EXPANDED ); |
72 |
setExpanded : function( expanded ) { |
| 73 |
} else { |
73 |
this._expanded = expanded; |
| 74 |
this._chevron.removeState( org.eclipse.swt.widgets.ExpandItem.STATE_EXPANDED ); |
74 |
if( expanded ) { |
| 75 |
} |
75 |
this._chevron.addState( org.eclipse.swt.widgets.ExpandItem.STATE_EXPANDED ); |
| 76 |
}, |
76 |
} else { |
| 77 |
|
77 |
this._chevron.removeState( org.eclipse.swt.widgets.ExpandItem.STATE_EXPANDED ); |
| 78 |
setImage : function( image ) { |
78 |
} |
| 79 |
this._image = image; |
79 |
}, |
| 80 |
this._header.setIcon( image ); |
80 |
|
| 81 |
}, |
81 |
setImage : function( image ) { |
| 82 |
|
82 |
this._image = image; |
| 83 |
setText : function( text ) { |
83 |
this._header.setIcon( image ); |
| 84 |
this._text = text; |
84 |
}, |
| 85 |
this._header.setLabel( text ); |
85 |
|
| 86 |
}, |
86 |
setText : function( text ) { |
| 87 |
|
87 |
this._text = text; |
| 88 |
setHeaderHeight : function( headerHeight ) { |
88 |
this._header.setLabel( text ); |
| 89 |
this._headerHeight = headerHeight; |
89 |
}, |
| 90 |
this._header.setHeight( this._headerHeight ); |
90 |
|
| 91 |
this._chevron.setTop( ( this._headerHeight - this._chevron.getHeight() ) / 2 ); |
91 |
setHeaderHeight : function( headerHeight ) { |
| 92 |
}, |
92 |
this._headerHeight = headerHeight; |
| 93 |
|
93 |
this._header.setHeight( this._headerHeight ); |
| 94 |
_onClick : function( evt ) { |
94 |
this._chevron.setTop( ( this._headerHeight - this._chevron.getHeight() ) / 2 ); |
| 95 |
if( !org_eclipse_rap_rwt_EventUtil_suspend ) { |
95 |
}, |
| 96 |
var widgetManager = org.eclipse.swt.WidgetManager.getInstance(); |
96 |
|
| 97 |
var req = org.eclipse.swt.Request.getInstance(); |
97 |
_onClick : function( evt ) { |
| 98 |
var id = widgetManager.findIdByWidget( this ); |
98 |
if( !org_eclipse_rap_rwt_EventUtil_suspend ) { |
| 99 |
if( this._expanded ) { |
99 |
var widgetManager = org.eclipse.swt.WidgetManager.getInstance(); |
| 100 |
req.addEvent( "org.eclipse.swt.events.expandItemCollapsed", id ); |
100 |
var req = org.eclipse.swt.Request.getInstance(); |
| 101 |
} else { |
101 |
var id = widgetManager.findIdByWidget( this ); |
| 102 |
req.addEvent( "org.eclipse.swt.events.expandItemExpanded", id ); |
102 |
if( this._expanded ) { |
| 103 |
} |
103 |
req.addEvent( "org.eclipse.swt.events.expandItemCollapsed", id ); |
| 104 |
req.send(); |
104 |
} else { |
| 105 |
} |
105 |
req.addEvent( "org.eclipse.swt.events.expandItemExpanded", id ); |
| 106 |
}, |
106 |
} |
| 107 |
|
107 |
req.send(); |
| 108 |
_onContextMenu : function( evt ) { |
108 |
} |
| 109 |
var menu = this._expandBar.getContextMenu(); |
109 |
}, |
| 110 |
if( menu != null ) { |
110 |
|
| 111 |
menu.setLocation( evt.getPageX(), evt.getPageY() ); |
111 |
_onContextMenu : function( evt ) { |
| 112 |
menu.setOpener( this._expandBar ); |
112 |
var menu = this._expandBar.getContextMenu(); |
| 113 |
menu.show(); |
113 |
if( menu != null ) { |
| 114 |
evt.stopPropagation(); |
114 |
menu.setLocation( evt.getPageX(), evt.getPageY() ); |
| 115 |
} |
115 |
menu.setOpener( this._expandBar ); |
| 116 |
}, |
116 |
menu.show(); |
| 117 |
|
117 |
evt.stopPropagation(); |
| 118 |
_onHandleMouseOver : function( evt ) { |
118 |
} |
| 119 |
this._chevron.addState( org.eclipse.swt.widgets.ExpandItem.STATE_OVER ); |
119 |
}, |
| 120 |
}, |
120 |
|
| 121 |
|
121 |
_onHandleMouseOver : function( evt ) { |
| 122 |
_onHandleMouseOut : function( evt ) { |
122 |
this._chevron.addState( org.eclipse.swt.widgets.ExpandItem.STATE_OVER ); |
| 123 |
this._chevron.removeState( org.eclipse.swt.widgets.ExpandItem.STATE_OVER ); |
123 |
}, |
| 124 |
} |
124 |
|
| 125 |
} |
125 |
_onHandleMouseOut : function( evt ) { |
| 126 |
} ); |
126 |
this._chevron.removeState( org.eclipse.swt.widgets.ExpandItem.STATE_OVER ); |
|
|
127 |
} |
| 128 |
} |
| 129 |
} ); |