Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4d2bb595f67bf788b6d35baa5f568ec7f00692ff (plain) (blame)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.command.internal.env.ui.widgets;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;



public class SimpleWizardPage extends WizardPage implements PageWizardDataEvents
{
  private   WidgetContributor widget_;
  private   WidgetDataEvents  dataEvents_;
  private   Listener          statusListener_;
  protected WizardPageManager pageManager_;
  	
  public SimpleWizardPage( PageInfo pageInfo, WizardPageManager pageManager )
  {
  	super( "" );
  	
  	setTitle( pageInfo.getPageName() );
  	setDescription( pageInfo.getPageTitle());
  	  
  	widget_         = pageInfo.getWidgetFactory().create();
  	statusListener_ = new StatusListener();
  	pageManager_    = pageManager;
  } 	  
  	
  public void createControl( Composite parent ) 
  {
  	Composite control = new Composite( parent, SWT.NONE );
  	control.setLayout( new GridLayout() );
  	control.setLayoutData( new GridData( GridData.FILL_BOTH ));
  	
	dataEvents_ = widget_.addControls( control, statusListener_ );
	  
    org.eclipse.jface.dialogs.Dialog.applyDialogFont(control);
    setControl( control );
  }
  
  public WidgetDataEvents getDataEvents()
  {
    return dataEvents_;
  }
  	  
  public void validatePageToStatus()
  {
    IStatus status  = widget_.getStatus();
    
    if( status != null )
    {
      if( status.getSeverity() == IStatus.ERROR )
      {
        String message = status.getMessage();

        if( message.length() == 0 )
        {
          setErrorMessage( null );
          setMessage( getDescription() );
        }
        else
        {
          setErrorMessage( message );
        }
          
        setPageComplete( false );
      }
      else if (status.getSeverity() == IStatus.WARNING )
      {
        setErrorMessage( null );
        setMessage(status.getMessage(), IStatus.WARNING );
        setPageComplete( true );
      }
      else if( status.getSeverity() == IStatus.INFO )
      {
        setErrorMessage( null );
        setMessage( status.getMessage(), IStatus.INFO );
        setPageComplete( true );
      }
      else
      {
        setErrorMessage( null );
        setMessage( getDescription() );
        setPageComplete( true );
      }
    }
    else
    {
      setErrorMessage( null );
      setMessage( getDescription() );
      setPageComplete( true );
    }
    
    getContainer().updateButtons();
  }
    
  public boolean canFlipToNextPage() 
  {
	return isPageComplete() && pageManager_.hasNextPage();
  }

  public IWizardPage getNextPage() 
  {
	return pageManager_.getNextPage();
  }
  
  public void setVisible(boolean value) 
  {
  	pageManager_.handlePageVisible( this, value );
  	
    super.setVisible(value);
  }
  
  private class StatusListener implements Listener
  {
	public void handleEvent( Event evt ) 
	{
      validatePageToStatus();
	}
  }
}  

Back to the top