Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/vinculum/processeditor/ProcessWizardPage1.java


1   /* * ** **  BEGIN LICENSE BLOCK * ** **
2    * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3    *
4    * The contents of this file are subject to the Mozilla Public License Version 
5    * 1.1 (the "License"); you may not use this file except in compliance with 
6    * the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis,
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11   * for the specific language governing rights and limitations under the
12   * License.
13   *
14   * The Original Code is Vinculum Open Source.
15   *
16   * The Initial Developer of the Original Code is
17   * Gerard Toonstra.
18   * Portions created by the Initial Developer are Copyright (C) 2003
19   * the Initial Developer. All Rights Reserved.
20   *
21   * Contributor(s):
22   *
23   * Alternatively, the contents of this file may be used under the terms of
24   * either the GNU General Public License Version 2 or later (the "GPL"), or
25   * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26   * in which case the provisions of the GPL or the LGPL are applicable instead
27   * of those above. If you wish to allow use of your version of this file only
28   * under the terms of either the GPL or the LGPL, and not to allow others to
29   * use your version of this file under the terms of the MPL, indicate your
30   * decision by deleting the provisions above and replace them with the notice
31   * and other provisions required by the GPL or the LGPL. If you do not delete
32   * the provisions above, a recipient may use your version of this file under
33   * the terms of any one of the MPL, the GPL or the LGPL.
34   *
35   * ** ** * END LICENSE BLOCK * ** **
36   */
37  
38  /***************************************************************************
39                            $RCSfile: ProcessWizardPage1.java,v $  -  description
40                               -------------------
41      begin                : $Date: 2003/07/08 08:02:08 $
42      copyright            : Vinculum (C) 2002
43      author               : $Author: chiraz $
44   ***************************************************************************/
45  
46  /* $Log: ProcessWizardPage1.java,v $
47  /* Revision 1.1.1.1  2003/07/08 08:02:08  chiraz
48  /* egg
49  /* */
50  
51  package com.vinculum.processeditor;
52  
53  import java.io.ByteArrayInputStream;
54  import java.io.ByteArrayOutputStream;
55  import java.io.InputStream;
56  import java.io.ObjectOutputStream;
57  
58  import org.eclipse.core.resources.IFile;
59  import org.eclipse.jface.resource.ImageDescriptor;
60  import org.eclipse.jface.viewers.IStructuredSelection;
61  import org.eclipse.swt.SWT;
62  import org.eclipse.swt.events.SelectionEvent;
63  import org.eclipse.swt.events.SelectionListener;
64  import org.eclipse.swt.layout.GridData;
65  import org.eclipse.swt.layout.GridLayout;
66  import org.eclipse.swt.widgets.Button;
67  import org.eclipse.swt.widgets.Composite;
68  import org.eclipse.swt.widgets.Group;
69  import org.eclipse.swt.widgets.Label;
70  import org.eclipse.ui.IWorkbench;
71  import org.eclipse.ui.IWorkbenchPage;
72  import org.eclipse.ui.IWorkbenchWindow;
73  import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
74  
75  import com.vinculum.processeditor.model.ProcessDiagram;
76  import com.vinculum.processeditor.model.ProcessDiagramFactory;
77  
78  /**
79   * @author chilan
80   *
81   */
82  public class ProcessWizardPage1
83    extends WizardNewFileCreationPage
84    implements SelectionListener
85  {
86    private IWorkbench  workbench;
87    private static int exampleCount = 1;
88    private Button model1 = null;
89    private Button model2 = null;
90    private int modelSelected = 1;
91  
92    public ProcessWizardPage1(IWorkbench aWorkbench, IStructuredSelection selection) 
93    {
94      super("sampleLogicPage1", selection);  //$NON-NLS-1$
95      this.setTitle(ProcessMessages.CreateLogicPage1_Title);
96      this.setDescription(ProcessMessages.CreateLogicPage1_Description);
97      this.setImageDescriptor(ImageDescriptor.createFromFile(getClass(),"icons/logic.gif"));  //$NON-NLS-1$
98      this.workbench = aWorkbench;
99    }
100 
101   public void createControl(Composite parent) 
102   {
103     super.createControl(parent);
104     this.setFileName("emptyModel" + exampleCount + ".logic");  //$NON-NLS-2$//$NON-NLS-1$
105   
106     Composite composite = (Composite)getControl();
107   
108     new Label(composite,SWT.NONE);
109   
110     // sample section generation group
111     Group group = new Group(composite,SWT.NONE);
112     group.setLayout(new GridLayout());
113     group.setText(ProcessMessages.CreateLogicPage1_ModelNames_GroupName); 
114     group.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
115   
116     // sample section generation checkboxes
117     model1 = new Button(group,SWT.RADIO);
118     model1.setText(ProcessMessages.CreateLogicPage1_ModelNames_EmptyModelName);
119     model1.addSelectionListener(this);
120     model1.setSelection(true);
121 
122     model2 = new Button(group,SWT.RADIO);
123     model2.setText(ProcessMessages.CreateLogicPage1_ModelNames_FourBitAdderModelName);
124     model2.addSelectionListener(this);
125   
126     new Label(composite,SWT.NONE);
127   
128     setPageComplete(validatePage());
129   }
130 
131   protected InputStream getInitialContents() 
132   {
133     ProcessDiagram pd = new ProcessDiagram();
134     if (modelSelected == 2)
135         pd = (ProcessDiagram)ProcessDiagramFactory.createLargeModel();
136     ByteArrayInputStream bais = null;
137     try 
138     {
139       ByteArrayOutputStream baos = new ByteArrayOutputStream();
140       ObjectOutputStream oos = new ObjectOutputStream(baos);
141       oos.writeObject(pd);
142       oos.flush();
143       oos.close();
144       baos.close();
145       bais = new ByteArrayInputStream(baos.toByteArray());
146       bais.close();
147     }
148     catch(Exception e) 
149     {
150       e.printStackTrace();
151     }
152     return bais;
153   }
154 
155   public boolean finish() 
156   {
157     IFile newFile = createNewFile();
158     if (newFile == null) 
159       return false;  // ie.- creation was unsuccessful
160 
161     // Since the file resource was created fine, open it for editing
162     // iff requested by the user
163     try 
164     {
165       IWorkbenchWindow dwindow = workbench.getActiveWorkbenchWindow();
166       IWorkbenchPage page = dwindow.getActivePage();
167       if (page != null) 
168         page.openEditor(newFile);
169     } 
170     catch (org.eclipse.ui.PartInitException e) 
171     {
172       e.printStackTrace();
173       return false;
174     }
175     exampleCount++;
176     return true;
177   }
178 
179   /**
180    * @see org.eclipse.swt.events.SelectionListener#widgetSelected(SelectionEvent)
181    */
182   public void widgetSelected(SelectionEvent e) 
183   {
184     if( e.getSource() == model1 )
185     {
186       modelSelected = 1;
187       setFileName("emptyModel" + exampleCount + ".logic");  //$NON-NLS-2$//$NON-NLS-1$
188     } 
189     else 
190     {
191       modelSelected = 2;
192       setFileName("fourBitAdder" + exampleCount + ".logic");  //$NON-NLS-2$//$NON-NLS-1$
193     }
194   }
195 
196   /**
197    * Empty method
198    */
199   public void widgetDefaultSelected(SelectionEvent e)
200   {
201   }
202 }