Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/OldClient/src/org/litesoft/GWT/client/widgets/ContextMenuPopup.java

Diff revisions: vs.
  @@ -1,115 +1,115 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.client.widgets;
3 -
4 - import org.litesoft.GWT.client.*;
5 - import org.litesoft.GWT.client.commands.*;
6 - import org.litesoft.GWT.client.widgets.nonpublic.*;
7 - import org.litesoft.commonfoundation.typeutils.Objects;
8 -
9 - import com.google.gwt.user.client.*;
10 - import com.google.gwt.user.client.ui.*;
11 -
12 - import java.util.*;
13 -
14 - public class ContextMenuPopup extends AbstractContextPopup {
15 - public ContextMenuPopup() {
16 - super( true );
17 - }
18 -
19 - public ContextMenuPopup( PopupListener pListener ) {
20 - this();
21 - if ( pListener != null ) {
22 - addPopupListener( pListener );
23 - }
24 - }
25 -
26 - public ContextMenuPopup( IMenuableDef[] pMenuables ) {
27 - this( pMenuables, null );
28 - }
29 -
30 - public ContextMenuPopup( IMenuableDef[] pMenuables, PopupListener pListener ) {
31 - this( pListener );
32 - setMenuables( pMenuables );
33 - }
34 -
35 - public void setMenuables( final IMenuableDef[] pMenuables ) {
36 - Objects.assertNotNull( "IMenuableDefs", pMenuables );
37 -
38 - boolean hasIconURL = false;
39 - final List zCmds = new ArrayList();
40 - for ( int i = 0; i < pMenuables.length; i++ ) {
41 - IMenuableDef zDef = pMenuables[i];
42 - if ( zDef != null ) {
43 - IconTextCommand zCmd;
44 - if ( zDef instanceof IconTextCommand ) {
45 - zCmd = (IconTextCommand) zDef;
46 - } else if ( zDef instanceof TextCommand ) {
47 - zCmd = new CMTCproxy( (TextCommand) zDef );
48 - } else {
49 - continue;
50 - }
51 - hasIconURL |= zCmd.hasIconURL();
52 - zCmds.add( zCmd );
53 - }
54 - }
55 - if ( zCmds.isEmpty() ) {
56 - throw new IllegalArgumentException( "No MenuableDefs provided" );
57 - }
58 - mGrid = new TightGrid( zCmds.size(), hasIconURL ? 2 : 1 );
59 - for ( int i = 0; i < zCmds.size(); i++ ) {
60 - IconTextCommand zCmd = (IconTextCommand) zCmds.get( i );
61 -
62 - int col = 0;
63 - if ( hasIconURL ) {
64 - String url = zCmd.getIconURL();
65 - Image icon = new Image( url );
66 - mGrid.setWidget( i, col++, icon );
67 - }
68 - Label txtLabel = new Label( zCmd.getText() );
69 - mGrid.setWidget( i, col, txtLabel );
70 - }
71 - mGrid.setOnBrowserEventListener( Event.MOUSEEVENTS, new OnBrowserEventListener() {
72 - public boolean onBrowserEvent( Event event ) {
73 - switch ( DOM.eventGetType( event ) ) {
74 - case Event.ONMOUSEUP:
75 - UtilsGwt.eventPreventDefaultAndCancelBubble( event );
76 -
77 - // todo...
78 -
79 - case Event.ONMOUSEOVER:
80 - case Event.ONMOUSEOUT:
81 - case Event.ONMOUSEDOWN:
82 - case Event.ONMOUSEMOVE:
83 - default:
84 - break;
85 - }
86 - return false;
87 - }
88 - } );
89 - mGrid.addTableListener( new TableListener() {
90 - public void onCellClicked( SourcesTableEvents sender, int row, int cell ) {
91 - DeferredCommand.addCommand( (Command) zCmds.get( row ) );
92 - hide();
93 - }
94 - } );
95 - }
96 -
97 - private TightGrid mGrid = null;
98 -
99 - protected Widget createPopupWidget() {
100 - return mGrid;
101 - }
102 -
103 - private static class CMTCproxy extends IconTextCommand {
104 - private TextCommand mTextCommand;
105 -
106 - public CMTCproxy( TextCommand pTextCommand ) {
107 - super( null, pTextCommand.getText() );
108 - mTextCommand = pTextCommand;
109 - }
110 -
111 - public void enabledExecute() {
112 - mTextCommand.enabledExecute();
113 - }
114 - }
115 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.client.widgets;
3 +
4 + import org.litesoft.GWT.client.*;
5 + import org.litesoft.GWT.client.commands.*;
6 + import org.litesoft.GWT.client.widgets.nonpublic.*;
7 + import org.litesoft.commonfoundation.base.*;
8 +
9 + import com.google.gwt.user.client.*;
10 + import com.google.gwt.user.client.ui.*;
11 +
12 + import java.util.*;
13 +
14 + public class ContextMenuPopup extends AbstractContextPopup {
15 + public ContextMenuPopup() {
16 + super( true );
17 + }
18 +
19 + public ContextMenuPopup( PopupListener pListener ) {
20 + this();
21 + if ( pListener != null ) {
22 + addPopupListener( pListener );
23 + }
24 + }
25 +
26 + public ContextMenuPopup( IMenuableDef[] pMenuables ) {
27 + this( pMenuables, null );
28 + }
29 +
30 + public ContextMenuPopup( IMenuableDef[] pMenuables, PopupListener pListener ) {
31 + this( pListener );
32 + setMenuables( pMenuables );
33 + }
34 +
35 + public void setMenuables( final IMenuableDef[] pMenuables ) {
36 + Confirm.isNotNull( "IMenuableDefs", pMenuables );
37 +
38 + boolean hasIconURL = false;
39 + final List zCmds = new ArrayList();
40 + for ( int i = 0; i < pMenuables.length; i++ ) {
41 + IMenuableDef zDef = pMenuables[i];
42 + if ( zDef != null ) {
43 + IconTextCommand zCmd;
44 + if ( zDef instanceof IconTextCommand ) {
45 + zCmd = (IconTextCommand) zDef;
46 + } else if ( zDef instanceof TextCommand ) {
47 + zCmd = new CMTCproxy( (TextCommand) zDef );
48 + } else {
49 + continue;
50 + }
51 + hasIconURL |= zCmd.hasIconURL();
52 + zCmds.add( zCmd );
53 + }
54 + }
55 + if ( zCmds.isEmpty() ) {
56 + throw new IllegalArgumentException( "No MenuableDefs provided" );
57 + }
58 + mGrid = new TightGrid( zCmds.size(), hasIconURL ? 2 : 1 );
59 + for ( int i = 0; i < zCmds.size(); i++ ) {
60 + IconTextCommand zCmd = (IconTextCommand) zCmds.get( i );
61 +
62 + int col = 0;
63 + if ( hasIconURL ) {
64 + String url = zCmd.getIconURL();
65 + Image icon = new Image( url );
66 + mGrid.setWidget( i, col++, icon );
67 + }
68 + Label txtLabel = new Label( zCmd.getText() );
69 + mGrid.setWidget( i, col, txtLabel );
70 + }
71 + mGrid.setOnBrowserEventListener( Event.MOUSEEVENTS, new OnBrowserEventListener() {
72 + public boolean onBrowserEvent( Event event ) {
73 + switch ( DOM.eventGetType( event ) ) {
74 + case Event.ONMOUSEUP:
75 + UtilsGwt.eventPreventDefaultAndCancelBubble( event );
76 +
77 + // todo...
78 +
79 + case Event.ONMOUSEOVER:
80 + case Event.ONMOUSEOUT:
81 + case Event.ONMOUSEDOWN:
82 + case Event.ONMOUSEMOVE:
83 + default:
84 + break;
85 + }
86 + return false;
87 + }
88 + } );
89 + mGrid.addTableListener( new TableListener() {
90 + public void onCellClicked( SourcesTableEvents sender, int row, int cell ) {
91 + DeferredCommand.addCommand( (Command) zCmds.get( row ) );
92 + hide();
93 + }
94 + } );
95 + }
96 +
97 + private TightGrid mGrid = null;
98 +
99 + protected Widget createPopupWidget() {
100 + return mGrid;
101 + }
102 +
103 + private static class CMTCproxy extends IconTextCommand {
104 + private TextCommand mTextCommand;
105 +
106 + public CMTCproxy( TextCommand pTextCommand ) {
107 + super( null, pTextCommand.getText() );
108 + mTextCommand = pTextCommand;
109 + }
110 +
111 + public void enabledExecute() {
112 + mTextCommand.enabledExecute();
113 + }
114 + }
115 + }