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 279133
Collapse All | Expand All

(-)src/org/eclipse/rap/internal/design/example/business/stacks/ViewStackPresentation.java (-12 / +68 lines)
Lines 42-47 Link Here
42
import org.eclipse.swt.widgets.Label;
42
import org.eclipse.swt.widgets.Label;
43
import org.eclipse.swt.widgets.Listener;
43
import org.eclipse.swt.widgets.Listener;
44
import org.eclipse.swt.widgets.Shell;
44
import org.eclipse.swt.widgets.Shell;
45
import org.eclipse.ui.IPropertyListener;
46
import org.eclipse.ui.ISaveablePart;
45
import org.eclipse.ui.IWorkbench;
47
import org.eclipse.ui.IWorkbench;
46
import org.eclipse.ui.IWorkbenchPage;
48
import org.eclipse.ui.IWorkbenchPage;
47
import org.eclipse.ui.IWorkbenchPart;
49
import org.eclipse.ui.IWorkbenchPart;
Lines 66-72 Link Here
66
  private Button confButton;
68
  private Button confButton;
67
  private Label confCorner;
69
  private Label confCorner;
68
  private Map buttonPartMap = new HashMap();
70
  private Map buttonPartMap = new HashMap();
69
  private IPresentablePart lastPart;
70
  private List partList = new ArrayList();
71
  private List partList = new ArrayList();
71
  private List buttonList = new ArrayList();
72
  private List buttonList = new ArrayList();
72
  private Composite toolbarBg;
73
  private Composite toolbarBg;
Lines 74-79 Link Here
74
  private int state;
75
  private int state;
75
  protected boolean deactivated;
76
  protected boolean deactivated;
76
  private Button viewMenuButton;
77
  private Button viewMenuButton;
78
  private Map dirtyListenerMap = new HashMap();
79
  
80
  private class DirtyListener implements IPropertyListener {
81
    
82
    private IPresentablePart part;
83
    
84
    public DirtyListener( final IPresentablePart part ) {
85
      this.part = part;
86
    }
87
    
88
    public void propertyChanged( Object source, int propId ) {
89
      if( propId == ISaveablePart.PROP_DIRTY ) {  
90
        Button partButton = getPartButton( part );
91
        if( partButton != null ) {
92
          String text = partButton.getText();
93
          char lastCharacter = getLastCharacter( text );
94
          if( part.isDirty() ) {
95
            // mark the part as dirty                                        
96
            if( lastCharacter != '*') {
97
              text = text + "*";
98
            }
99
          } else {
100
            // mark the part as clean
101
            if( lastCharacter == '*' ) {
102
              text = text.substring( 0, text.length() - 1 );
103
            }
104
          }
105
          partButton.setText( text );
106
        }
107
      }
108
    }
109
    
110
    private Button getPartButton( final IPresentablePart part ) {
111
      Button result = null;
112
      Object object = buttonPartMap.get( part );
113
      if( object instanceof Composite ) {
114
        Control[] children = ( ( Composite ) object ).getChildren();
115
        if( children.length > 0 && children[ 0 ] instanceof Button ) {
116
          result = ( Button ) children[ 0 ];
117
        }
118
      }
119
      return result;
120
    }
121
    
122
    private char getLastCharacter( final String text ) {
123
      char[] starArray = new char[ 1 ];
124
      text.getChars( text.length()-1, text.length(), starArray, 0);
125
      return starArray[ 0 ];
126
    }
127
  };
77
128
78
  public ViewStackPresentation() {
129
  public ViewStackPresentation() {
79
    state = AS_INACTIVE;
130
    state = AS_INACTIVE;
Lines 154-160 Link Here
154
    } else {
205
    } else {
155
      decorateStandaloneView( newPart );
206
      decorateStandaloneView( newPart );
156
    }
207
    }
157
    
208
    // add the lsitener for the dirty state
209
    IPropertyListener listener = new DirtyListener( newPart );
210
    dirtyListenerMap .put( newPart, listener );
211
    newPart.addPropertyListener( listener );
158
  }
212
  }
159
  
213
  
160
  private void decorateStandaloneView( final IPresentablePart newPart ) {
214
  private void decorateStandaloneView( final IPresentablePart newPart ) {
Lines 349-355 Link Here
349
            close.setData( WidgetUtil.CUSTOM_VARIANT, "clearButton" );
403
            close.setData( WidgetUtil.CUSTOM_VARIANT, "clearButton" );
350
            close.addSelectionListener( new SelectionAdapter() {
404
            close.addSelectionListener( new SelectionAdapter() {
351
              public void widgetSelected( SelectionEvent e ) {
405
              public void widgetSelected( SelectionEvent e ) {
352
                removePart( part );
406
                getSite().close( new IPresentablePart[] { part } );
353
              };
407
              };
354
            } );
408
            } );
355
            FormData fdClose = new FormData();
409
            FormData fdClose = new FormData();
Lines 529-544 Link Here
529
583
530
  public void removePart( final IPresentablePart oldPart ) {
584
  public void removePart( final IPresentablePart oldPart ) {
531
    Object object = buttonPartMap.get( oldPart );
585
    Object object = buttonPartMap.get( oldPart );
586
    // remove the dirtyListener
587
    Object listener = dirtyListenerMap.get( oldPart );
588
    if( listener != null && listener instanceof IPropertyListener ) {
589
      oldPart.removePropertyListener( ( IPropertyListener ) listener ); 
590
    }
532
    buttonPartMap.remove( oldPart );
591
    buttonPartMap.remove( oldPart );
533
    buttonList.remove( object );
592
    buttonList.remove( object );
534
    ( ( Composite ) object ).dispose(); 
593
    ( ( Composite ) object ).dispose(); 
535
    partList.remove( oldPart );
594
    partList.remove( oldPart );
536
    if( lastPart != null ) {
595
    oldPart.setVisible( false );
537
      selectPart( lastPart );
538
    } else if( partList.size() > 0 ) {
539
      IPresentablePart newPart = ( IPresentablePart ) partList.get( 0 );
540
      selectPart( newPart );
541
    }
542
    tabBg.layout();
596
    tabBg.layout();
543
  }
597
  }
544
598
Lines 546-556 Link Here
546
    if( toSelect != null ) {
600
    if( toSelect != null ) {
547
      toSelect.setVisible( true );
601
      toSelect.setVisible( true );
548
    }
602
    }
549
    if( currentPart != null ) {
603
    if( currentPart != null  ) {
550
      currentPart.setVisible( false );
604
      if( currentPart instanceof PresentablePart 
605
          && ( (PresentablePart) currentPart ).getPane() != null ) {
606
        currentPart.setVisible( false ); 
607
      }
551
    }
608
    }
552
    makePartButtonInactive( currentPart );
609
    makePartButtonInactive( currentPart );
553
    lastPart = currentPart;
554
    currentPart = toSelect;
610
    currentPart = toSelect;
555
    makePartButtonActive( currentPart );
611
    makePartButtonActive( currentPart );
556
    activePart( currentPart );
612
    activePart( currentPart );

Return to bug 279133