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

Quick Search    Search Deep

Source code: com/vinculum/processeditor/wizards/VCMpageOne.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   * Copyright (c) 2000, 2003 IBM Corporation and others.
40   * All rights reserved. This program and the accompanying materials 
41   * are made available under the terms of the Common Public License v1.0
42   * which accompanies this distribution, and is available at
43   * http://www.eclipse.org/legal/cpl-v10.html
44   * 
45   * Contributors:
46   *     IBM Corporation - initial API and implementation
47   *******************************************************************************/
48  package com.vinculum.processeditor.wizards;
49  
50  import java.io.ByteArrayInputStream;
51  import java.io.ByteArrayOutputStream;
52  import java.io.InputStream;
53  import java.io.ObjectOutputStream;
54  
55  import org.eclipse.swt.widgets.*;
56  import org.eclipse.swt.layout.*;
57  import org.eclipse.swt.SWT;
58  import org.eclipse.core.resources.*;
59  import org.eclipse.swt.events.*;
60  import org.eclipse.ui.IWorkbench;
61  import org.eclipse.ui.IWorkbenchPage;
62  import org.eclipse.ui.IWorkbenchWindow;
63  import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
64  import org.eclipse.jface.resource.ImageDescriptor;
65  import org.eclipse.jface.viewers.*;
66  
67  import com.vinculum.processeditor.ProcessMessages;
68  import com.vinculum.processeditor.model.ProcessDiagram;
69  import com.vinculum.processeditor.model.ProcessDiagramFactory;
70  
71  /**
72   * The "New" wizard page allows setting the container for
73   * the new file as well as the file name. The page
74   * will only accept file name without the extension OR
75   * with the extension that matches the expected one (vpd).
76   */
77  
78  public class VCMpageOne 
79    extends WizardNewFileCreationPage 
80    implements SelectionListener
81  {
82    private IWorkbench  workbench;
83    private static int exampleCount = 1;
84    private Button model1 = null;
85    private Button model2 = null;
86    private int modelSelected = 1;
87  
88    public VCMpageOne(IWorkbench aWorkbench, IStructuredSelection selection) 
89    {
90      super("VCMpageOne", selection);  //$NON-NLS-1$
91      this.setTitle(ProcessMessages.CreateVCMPage1_Title);
92      this.setDescription(ProcessMessages.CreateVCMPage1_Description);
93      // TODO: Set proper image
94      this.setImageDescriptor(ImageDescriptor.createFromFile(getClass(),"/icons/sample.gif"));  //$NON-NLS-1$
95      this.workbench = aWorkbench;
96    }
97  
98    public void createControl(Composite parent) 
99    {
100     super.createControl(parent);
101     this.setFileName("emptyModel" + exampleCount + ".vpd");  //$NON-NLS-2$//$NON-NLS-1$
102   
103     Composite composite = (Composite)getControl();
104   
105     new Label(composite,SWT.NONE);
106   
107     // sample section generation group
108     Group group = new Group(composite,SWT.NONE);
109     group.setLayout(new GridLayout());
110     group.setText(ProcessMessages.CreateVCMPage1_ModelNames_GroupName); 
111     group.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
112   
113     // sample section generation checkboxes
114     model1 = new Button(group,SWT.RADIO);
115     model1.setText(ProcessMessages.CreateVCMPage1_ModelNames_EmptyModelName);
116     model1.addSelectionListener(this);
117     model1.setSelection(true);
118 
119     model2 = new Button(group,SWT.RADIO);
120     model2.setText(ProcessMessages.CreateVCMPage1_ModelNames_FourBitAdderModelName);
121     model2.addSelectionListener(this);
122   
123     new Label(composite,SWT.NONE);
124   
125     setPageComplete(validatePage());
126   }
127 
128   protected InputStream getInitialContents() 
129   {
130     ProcessDiagram ld = new ProcessDiagram();
131     if (modelSelected == 2)
132         ld = (ProcessDiagram)ProcessDiagramFactory.createLargeModel();
133     ByteArrayInputStream bais = null;
134     try 
135     {
136       ByteArrayOutputStream baos = new ByteArrayOutputStream();
137       ObjectOutputStream oos = new ObjectOutputStream(baos);
138       oos.writeObject(ld);
139       oos.flush();
140       oos.close();
141       baos.close();
142       bais = new ByteArrayInputStream(baos.toByteArray());
143       bais.close();
144     }
145     catch(Exception e) 
146     {
147       e.printStackTrace();
148     }
149     return bais;
150   }
151 
152   public boolean finish() 
153   {
154     IFile newFile = createNewFile();
155     if (newFile == null) 
156       return false;  // ie.- creation was unsuccessful
157 
158     // Since the file resource was created fine, open it for editing
159     // iff requested by the user
160     try 
161     {
162       IWorkbenchWindow dwindow = workbench.getActiveWorkbenchWindow();
163       IWorkbenchPage page = dwindow.getActivePage();
164       if (page != null) 
165         page.openEditor(newFile);
166     } 
167     catch (org.eclipse.ui.PartInitException e) 
168     {
169       e.printStackTrace();
170       return false;
171     }
172     exampleCount++;
173     return true;
174   }
175 
176   /**
177    * @see org.eclipse.swt.events.SelectionListener#widgetSelected(SelectionEvent)
178    */
179   public void widgetSelected(SelectionEvent e) 
180   {
181     if( e.getSource() == model1 )
182     {
183       modelSelected = 1;
184       setFileName("emptyModel" + exampleCount + ".vpd");  //$NON-NLS-2$//$NON-NLS-1$
185     } 
186     else 
187     {
188       modelSelected = 2;
189       setFileName("fourBitAdder" + exampleCount + ".vpd");  //$NON-NLS-2$//$NON-NLS-1$
190     }
191   }
192   
193   /**
194    * Empty method
195    */
196   public void widgetDefaultSelected(SelectionEvent e) 
197   {
198   }
199 
200 }