Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 326159 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/rap/internal/design/example/managers/ViewToolBarManager.java (-89 / +99 lines)
Lines 1-4 Link Here
1
/******************************************************************************* 
1
/*******************************************************************************
2
* Copyright (c) 2008, 2010 EclipseSource and others. All rights reserved. This
2
* Copyright (c) 2008, 2010 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
Lines 6-96 Link Here
6
*
6
*
7
* Contributors:
7
* Contributors:
8
*   EclipseSource - initial API and implementation
8
*   EclipseSource - initial API and implementation
9
*******************************************************************************/ 
9
*******************************************************************************/
10
package org.eclipse.rap.internal.design.example.managers;
10
package org.eclipse.rap.internal.design.example.managers;
11
11
12
import java.util.ArrayList;
12
import java.util.ArrayList;
13
import java.util.Iterator;
13
import java.util.Iterator;
14
import java.util.List;
15
16
import org.eclipse.jface.action.IContributionItem;
14
import org.eclipse.jface.action.IContributionItem;
17
import org.eclipse.jface.internal.provisional.action.ToolBarManager2;
15
import org.eclipse.jface.internal.provisional.action.ToolBarManager2;
18
import org.eclipse.rwt.lifecycle.WidgetUtil;
16
import org.eclipse.rwt.lifecycle.WidgetUtil;
19
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Control;
19
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Menu;
23
import org.eclipse.swt.widgets.ToolBar;
20
import org.eclipse.swt.widgets.ToolBar;
24
import org.eclipse.swt.widgets.ToolItem;
21
import org.eclipse.swt.widgets.ToolItem;
25
22
26
23
27
public class ViewToolBarManager extends ToolBarManager2 {
24
public class ViewToolBarManager extends ToolBarManager2 {
28
  
29
  private static final String STYLING_VARIANT = "viewToolbar"; //$NON-NLS-1$
30
  private ToolBar toolBar;
31
  private ToolBar fakeToolbar;
32
25
26
  private static final String STYLING_VARIANT = "viewToolbar"; //$NON-NLS-1$
27
  private ToolBar fakeToolBar;
33
28
34
  public ToolBar createControl(Composite parent) {
29
  public ToolBar createControl( final Composite parent ) {
30
    ToolBar toolBar = getControl();
35
    if( !toolBarExist() && parent != null ) {
31
    if( !toolBarExist() && parent != null ) {
36
      toolBar = new ToolBar( parent, SWT.NONE );
32
      fakeToolBar = new ToolBar( parent, SWT.NONE );
33
      fakeToolBar.setVisible( false );
34
      toolBar = super.createControl( parent );
37
      toolBar.setData( WidgetUtil.CUSTOM_VARIANT, STYLING_VARIANT );
35
      toolBar.setData( WidgetUtil.CUSTOM_VARIANT, STYLING_VARIANT );
38
      toolBar.setMenu( getContextMenuControl() );
39
      // create the fake Toolbar
40
      fakeToolbar = new ToolBar( parent, SWT.NONE );
41
      fakeToolbar.setVisible( false );
42
      update( true );
43
    }
36
    }
44
    return toolBar;
37
    return toolBar;
45
  }
38
  }
46
  
39
47
  public ToolBar getControl() {
40
  public void dispose() {
48
    return toolBar;
41
    super.dispose();
49
  }
42
    if( fakeToolBar != null ) {
50
  
43
      fakeToolBar.dispose();
51
  private Menu getContextMenuControl() {
44
      fakeToolBar = null;
52
    Menu result = null;
53
    if( ( getContextMenuManager() != null ) && ( toolBar != null ) ) {
54
      Menu menuWidget = getContextMenuManager().getMenu();
55
      if( ( menuWidget == null ) || ( menuWidget.isDisposed() ) ) {
56
        menuWidget = getContextMenuManager().createContextMenu( toolBar);
57
      }
58
      result = menuWidget;
59
    }
45
    }
60
    return result;
61
  }
62
  
63
  private boolean toolBarExist() {
64
    return toolBar != null && !toolBar.isDisposed();
65
  }
46
  }
66
  
47
67
  /*
48
  public void update( final boolean force ) {
68
   * (non-Javadoc) Method declared on IContributionManager.
69
   */
70
  public void update( boolean force ) {
71
    if( isDirty() || force ) {
49
    if( isDirty() || force ) {
72
      if( toolBarExist() ) {
50
      if( toolBarExist() ) {
73
51
        ToolBar toolBar = getControl();
74
        // clean contains all active items without separators
52
        // clean contains all active items without double separators
75
        IContributionItem[] items = getItems();
53
        IContributionItem[] items = getItems();
76
        ArrayList clean = new ArrayList( items.length );
54
        ArrayList clean = new ArrayList(items.length);
55
        IContributionItem separator = null;
77
        for( int i = 0; i < items.length; ++i ) {
56
        for( int i = 0; i < items.length; ++i ) {
78
          IContributionItem ci = items[ i ];
57
          IContributionItem ci = items[ i ];
79
          if( !ci.isSeparator() ) {
58
          if( ci.isSeparator() ) {
59
            separator = ci;
60
          } else {
61
            if( separator != null ) {
62
              if( clean.size() > 0 ) {
63
                clean.add( separator );
64
              }
65
              separator = null;
66
            }
80
            clean.add( ci );
67
            clean.add( ci );
81
          }
68
          }
82
        }
69
        }
83
        // determine obsolete items (removed or non active)
70
        // determine obsolete items (removed or non active)
84
        ToolItem[] mi = toolBar.getItems();
71
        ToolItem[] mi = toolBar.getItems();
85
        ArrayList toRemove = new ArrayList();
72
        ArrayList toRemove = new ArrayList( mi.length );
86
        for( int i = 0; i < mi.length; i++ ) {
73
        for( int i = 0; i < mi.length; i++ ) {
87
          toRemove.add( mi[ i ] );
74
          // there may be null items in a toolbar
88
        }
75
          if( mi[ i ] == null ) {
89
        // add fake toolbar items to the items to remove
76
            continue;
90
        for( int i = 0; i < fakeToolbar.getItemCount(); i++ ) {
77
          }
91
          toRemove.add( fakeToolbar.getItem( i ) );
78
          Object data = mi[ i ].getData();
79
          if( data == null
80
              || !clean.contains( data )
81
              || ( data instanceof IContributionItem && ( ( IContributionItem ) data)
82
                  .isDynamic() ) ) {
83
            toRemove.add( mi[ i ] );
84
          }
92
        }
85
        }
93
94
        // Turn redraw off if the number of items to be added
86
        // Turn redraw off if the number of items to be added
95
        // is above a certain threshold, to minimize flicker,
87
        // is above a certain threshold, to minimize flicker,
96
        // otherwise the toolbar can be seen to redraw after each item.
88
        // otherwise the toolbar can be seen to redraw after each item.
Lines 102-111 Link Here
102
          if( useRedraw ) {
94
          if( useRedraw ) {
103
            toolBar.setRedraw( false );
95
            toolBar.setRedraw( false );
104
          }
96
          }
105
106
          // remove obsolete items
97
          // remove obsolete items
107
          for( int i = toRemove.size(); --i >= 0; ) {
98
          for (int i = toRemove.size(); --i >= 0;) {
108
            ToolItem item = ( ToolItem ) toRemove.get(i);
99
            ToolItem item = ( ToolItem )toRemove.get( i );
109
            if( !item.isDisposed() ) {
100
            if( !item.isDisposed() ) {
110
              Control ctrl = item.getControl();
101
              Control ctrl = item.getControl();
111
              if( ctrl != null ) {
102
              if( ctrl != null ) {
Lines 115-169 Link Here
115
              item.dispose();
106
              item.dispose();
116
            }
107
            }
117
          }
108
          }
118
119
          // add new items
109
          // add new items
120
          IContributionItem src, dest;
110
          IContributionItem src, dest;
121
          mi = toolBar.getItems();
111
          mi = toolBar.getItems();
122
          int srcIx = 0;
112
          int srcIx = 0;
123
          int destIx = 0;         
113
          int destIx = 0;
124
          
125
          for( Iterator e = clean.iterator(); e.hasNext(); ) {
114
          for( Iterator e = clean.iterator(); e.hasNext(); ) {
126
            src = ( IContributionItem )e.next();
115
            src = ( IContributionItem )e.next();
127
128
            // get corresponding item in SWT widget
116
            // get corresponding item in SWT widget
129
            if( srcIx < mi.length ) {
117
            if( srcIx < mi.length ) {
130
              dest = ( IContributionItem ) mi[ srcIx ].getData();
118
              dest = ( IContributionItem )mi[ srcIx ].getData();
131
            } else {
119
            } else {
132
              dest = null;
120
              dest = null;
133
            }
121
            }
134
135
            if( dest != null && src.equals( dest ) ) {
122
            if( dest != null && src.equals( dest ) ) {
136
              srcIx++;
123
              srcIx++;
137
              destIx++;
124
              destIx++;
138
              continue;
125
              continue;
139
            }
126
            }
140
127
            if( dest != null && dest.isSeparator() && src.isSeparator() ) {
141
            if(    dest != null && dest.isSeparator()
142
                && src.isSeparator() ) 
143
            {
144
              mi[ srcIx ].setData( src );
128
              mi[ srcIx ].setData( src );
145
              srcIx++;
129
              srcIx++;
146
              destIx++;
130
              destIx++;
147
              continue;
131
              continue;
148
            }
132
            }
149
133
            int start = toolBar.getItemCount();
150
            // fill item if visible, if not fill it into the fake toolbar
134
            src.fill( toolBar, destIx );
151
            ToolBar tempToolBar = null;
135
            int newItems = toolBar.getItemCount() - start;
152
            if( src.isVisible() ) {
136
            for( int i = 0; i < newItems; i++ ) {
153
              src.fill( toolBar, destIx );
137
              ToolItem item = toolBar.getItem( destIx++ );
154
              tempToolBar = toolBar;
138
              item.setData( src );
155
            } else {
156
              src.fill( fakeToolbar, destIx );
157
              tempToolBar = fakeToolbar;
158
            }
159
            // check necessary for bug 306741
160
            if( destIx >= 0 && destIx < tempToolBar.getItemCount() - 1 ) {
161
              ToolItem toolItem = tempToolBar.getItem( destIx );
162
              toolItem.setData( src );
163
              toolItem.setData( WidgetUtil.CUSTOM_VARIANT, STYLING_VARIANT );
164
            }
139
            }
165
          }
140
          }
166
167
          // remove any old tool items not accounted for
141
          // remove any old tool items not accounted for
168
          for( int i = mi.length; --i >= srcIx; ) {
142
          for( int i = mi.length; --i >= srcIx; ) {
169
            ToolItem item = mi[ i ];
143
            ToolItem item = mi[ i ];
Lines 176-183 Link Here
176
              item.dispose();
150
              item.dispose();
177
            }
151
            }
178
          }
152
          }
179
153
          setDirty(false);
180
          setDirty( false );
154
          updateFakeToolBar();
155
          disposeInvisibleItems();
181
        } finally {
156
        } finally {
182
          // turn redraw back on if we turned it off above
157
          // turn redraw back on if we turned it off above
183
          if( useRedraw ) {
158
          if( useRedraw ) {
Lines 187-202 Link Here
187
      }
162
      }
188
    }
163
    }
189
  }
164
  }
190
  
165
191
  public List getToolItems() {
166
  public ToolItem[] getToolItems() {
192
    List result = new ArrayList();
167
    return fakeToolBar.getItems();
193
    for( int i = 0; i < toolBar.getItemCount(); i++ ) {
168
  }
194
      result.add( toolBar.getItem( i ) );
169
170
  private boolean toolBarExist() {
171
    ToolBar toolBar = getControl();
172
    return toolBar != null && !toolBar.isDisposed();
173
  }
174
175
  private void updateFakeToolBar() {
176
    ToolBar toolBar = getControl();
177
    ToolItem[] items = fakeToolBar.getItems();
178
    for( int i = 0; i < items.length; i++ ) {
179
      items[ i ].dispose();
195
    }
180
    }
196
    for( int i = 0; i < fakeToolbar.getItemCount(); i++ ) {
181
    items = toolBar.getItems();
197
      result.add( fakeToolbar.getItem( i ) );
182
    for( int i = 0; i < items.length; i++ ) {
183
      ToolItem item = new ToolItem( fakeToolBar, items[ i ].getStyle() );
184
      item.setText( items[ i ].getText() );
185
      item.setToolTipText( items[ i ].getToolTipText() );
186
      item.setImage( items[ i ].getImage() );
187
      item.setData( items[ i ].getData() );
198
    }
188
    }
199
    return result;
200
  }
189
  }
201
190
191
  private void disposeInvisibleItems() {
192
    ToolBar toolBar = getControl();
193
    ToolItem[] items = toolBar.getItems();
194
    for( int i = 0; i < items.length; i++ ) {
195
      ToolItem item = items[ i ];
196
      if( !item.isDisposed() ) {
197
        Object data = item.getData();
198
        if( data instanceof IContributionItem ) {
199
          IContributionItem itemData = ( IContributionItem )data;
200
          if( !itemData.isVisible() ) {
201
            Control ctrl = item.getControl();
202
            if( ctrl != null ) {
203
              item.setControl( null );
204
              ctrl.dispose();
205
            }
206
            item.dispose();
207
          }
208
        }
209
      }
210
    }
211
  }
202
}
212
}
(-)src/org/eclipse/rap/internal/design/example/stacks/ConfigurationDialog.java (-10 / +10 lines)
Lines 112-118 Link Here
112
      = ( ConfigurableStack ) action.getStackPresentation();
112
      = ( ConfigurableStack ) action.getStackPresentation();
113
    IToolBarManager manager = stackPresentation.getPartToolBarManager();
113
    IToolBarManager manager = stackPresentation.getPartToolBarManager();
114
    if( manager != null ) {
114
    if( manager != null ) {
115
      manager.update( true );     
115
      manager.update( true );
116
    }
116
    }
117
    action.fireToolBarChange();
117
    action.fireToolBarChange();
118
    return super.close();
118
    return super.close();
Lines 161-167 Link Here
161
    fdOK.width = 90;
161
    fdOK.width = 90;
162
    ok.addSelectionListener( new SelectionAdapter() {
162
    ok.addSelectionListener( new SelectionAdapter() {
163
      public void widgetSelected( final SelectionEvent e ) {
163
      public void widgetSelected( final SelectionEvent e ) {
164
        close( true );       
164
        close( true );
165
      };
165
      };
166
    } );
166
    } );
167
    ok.moveAbove( cancel );
167
    ok.moveAbove( cancel );
Lines 209-220 Link Here
209
      String paneId = stackPresentation.getPaneId( site );
209
      String paneId = stackPresentation.getPaneId( site );
210
      if( manager instanceof ViewToolBarManager ) {
210
      if( manager instanceof ViewToolBarManager ) {
211
        //manager.update( true );
211
        //manager.update( true );
212
        List toolItems = ( ( ViewToolBarManager) manager ).getToolItems();
212
        ToolItem[] toolItems = ( ( ViewToolBarManager) manager ).getToolItems();
213
        for( int i = 0; i < toolItems.size(); i++ ) {
213
        for( int i = 0; i < toolItems.length; i++ ) {
214
          ToolItem item = ( ToolItem ) toolItems.get( i );
214
          ToolItem item = toolItems[ i ];
215
          if( item != null && !item.isDisposed() ) {
215
          if( item != null && !item.isDisposed() ) {
216
            // handle parameter
216
            // handle parameter
217
            IContributionItem contribItem 
217
            IContributionItem contribItem
218
              = ( IContributionItem ) item.getData();
218
              = ( IContributionItem ) item.getData();
219
            String itemId = contribItem.getId();
219
            String itemId = contribItem.getId();
220
            Image icon = item.getImage();
220
            Image icon = item.getImage();
Lines 224-230 Link Here
224
            } else {
224
            } else {
225
              text = item.getToolTipText();
225
              text = item.getToolTipText();
226
            }
226
            }
227
  
227
228
            // render the dialog
228
            // render the dialog
229
            Label imageLabel = new Label( container, SWT.NONE );
229
            Label imageLabel = new Label( container, SWT.NONE );
230
            imageLabel.setImage( icon );
230
            imageLabel.setImage( icon );
Lines 238-244 Link Here
238
              lastImageLabel = imageLabel;
238
              lastImageLabel = imageLabel;
239
            }
239
            }
240
            fdImageLabel.left = new FormAttachment( 0, OFFSET * 4 );
240
            fdImageLabel.left = new FormAttachment( 0, OFFSET * 4 );
241
  
241
242
            Button check = new Button( container, SWT.CHECK );
242
            Button check = new Button( container, SWT.CHECK );
243
            check.setText( text );
243
            check.setText( text );
244
            check.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
244
            check.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
Lines 259-270 Link Here
259
    }
259
    }
260
  }
260
  }
261
261
262
  public int open() {    
262
  public int open() {
263
    int result = super.open();
263
    int result = super.open();
264
    Shell shell = getShell();
264
    Shell shell = getShell();
265
    shell.setData( WidgetUtil.CUSTOM_VARIANT, "confDialog" ); //$NON-NLS-1$
265
    shell.setData( WidgetUtil.CUSTOM_VARIANT, "confDialog" ); //$NON-NLS-1$
266
    shell.setBackgroundMode( SWT.INHERIT_NONE );
266
    shell.setBackgroundMode( SWT.INHERIT_NONE );
267
    shell.setText( Messages.get().ConfigurationDialog_ConfigurationFor 
267
    shell.setText( Messages.get().ConfigurationDialog_ConfigurationFor
268
                   + site.getSelectedPart().getName() );
268
                   + site.getSelectedPart().getName() );
269
    String configDialogIcon = ILayoutSetConstants.CONFIG_DIALOG_ICON;
269
    String configDialogIcon = ILayoutSetConstants.CONFIG_DIALOG_ICON;
270
    shell.setImage( builder.getImage( configDialogIcon ) );
270
    shell.setImage( builder.getImage( configDialogIcon ) );

Return to bug 326159