Math2mat

/home/ythoma/docs/math2mat/svn/wp1/framework/m2mGUI/src/m2m/frontend/view/NavigationView.java

Go to the documentation of this file.
00001 
00020 package m2m.frontend.view;
00021 
00022 import java.io.File;
00023 
00024 import org.eclipse.core.filesystem.EFS;
00025 import org.eclipse.core.filesystem.IFileStore;
00026 import org.eclipse.core.runtime.CoreException;
00027 import org.eclipse.swt.SWT;
00028 import org.eclipse.swt.events.MouseEvent;
00029 import org.eclipse.swt.events.MouseListener;
00030 import org.eclipse.swt.widgets.Composite;
00031 import org.eclipse.swt.widgets.List;
00032 import org.eclipse.ui.IPartListener;
00033 import org.eclipse.ui.IWorkbenchPage;
00034 import org.eclipse.ui.IWorkbenchPart;
00035 import org.eclipse.ui.PlatformUI;
00036 import org.eclipse.ui.ide.FileStoreEditorInput;
00037 import org.eclipse.ui.part.ViewPart;
00038 
00039 import m2m.backend.project.M2MProject;
00040 import m2m.frontend.ApplicationActionBarAdvisor;
00041 import m2m.frontend.dynamicview.MyGraphicalEditor;
00042 import m2m.frontend.dynamicview.MyGraphicalProperty;
00043 
00044 
00045 public class NavigationView extends ViewPart {
00046         public static final String ID = "m2mgui.navigationView";
00047         private static List list;
00048         
00054         public static void addList (String path) {
00055                 list.add(path);
00056                 ApplicationActionBarAdvisor.getInstance().showOpenMenu(true);
00057         }
00058         
00064         public static void remList (String path) {
00065                 list.remove(path);
00066                 ApplicationActionBarAdvisor.getInstance().showOpenMenu(list.getItemCount()!=0);
00067         }
00068         
00075         public static void replaceList (String path, String newPath) {
00076                 int index = list.indexOf(path);
00077                 list.remove(path);
00078                 list.add(newPath, index);
00079         }
00080         
00085         public void createPartControl(Composite parent) {
00086                 //create the list
00087                 list = new List(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
00088                 
00089                 //add double clic listener to the list
00090                 list.addMouseListener(new MouseListener() {
00091                         @Override
00092                         public void mouseDoubleClick(MouseEvent e) {
00093                                 File file = new File(list.getItem(list.getFocusIndex()));
00094                                 
00095                                 M2MProject m2mProject = new M2MProject();
00096                                 m2mProject.openProject(file.getAbsolutePath());
00097                                 
00098                                 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
00099                                 try {
00100                                         IFileStore fileStore= EFS.getStore(m2mProject.getSourceFile().toURI());
00101                                         page.openEditor(new FileStoreEditorInput(fileStore), Editor.ID);
00102                                 } catch (CoreException e1) {
00103                                         e1.printStackTrace();
00104                                 }
00105                         }
00106 
00107                         @Override
00108                         public void mouseDown(MouseEvent e) {
00109                                 // TODO Auto-generated method stub
00110                                 
00111                         }
00112                         
00113                         @Override
00114                         public void mouseUp(MouseEvent e) {
00115                                 // TODO Auto-generated method stub
00116                                 
00117                         }
00118                 });
00119                 
00120                 //add listener that listen when a part of the page is activated
00121                 getSite().getPage().addPartListener(new IPartListener() {
00122 
00123                         @Override
00124                         public void partActivated(IWorkbenchPart part) {
00125                                 if (part instanceof Editor)
00126                                 {       
00127                                         //highlight the list item which correspond with the active editor
00128                                         list.setSelection(list.indexOf(((Editor)part).getM2MProject().getProperties().getProjectFullFilename()));
00129                                         getSite().getShell().getDisplay().asyncExec (new Runnable() {
00130                                                 public void run() {                                     
00131                                                 if (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() != null)
00132                                                 {                         
00133                                                 /* Get the structure of the editor */
00134                                                 Editor editor = (Editor)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
00135                                                 try 
00136                                                 {
00137                                                         /* Creation of two editors */
00138                                                     IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
00139                                                     MyGraphicalProperty graphProp = ((MyGraphicalProperty)page.findView(MyGraphicalProperty.ID));
00140                                                     MyGraphicalEditor graphEditor = ((MyGraphicalEditor)page.findView(MyGraphicalEditor.ID));
00141                                                     
00142                                                     if(editor.getModel() != null && graphProp != null)
00143                                                     {
00144                                                             graphProp.getGraphicalViewer().setContents(editor.getModel().getSchema());
00145                                                             graphEditor.getGraphicalViewer().setContents(editor.getModel().getSchema());
00146                                                     }
00147                                                     else if(editor.getModel() != null && graphProp == null)
00148                                                     {
00149                                                             page.showView(MyGraphicalEditor.ID);     
00150                                                             page.showView(MyGraphicalProperty.ID);   
00151                                                             setFocus();
00152                                                     }
00153                                                     else if(editor.getModel() == null && graphProp != null)
00154                                                     {
00155                                                         page.hideView(graphProp);     
00156                                                             page.hideView(graphEditor);   
00157                                                     }
00158                                                 } 
00159                                                 catch (Exception e) 
00160                                                 {
00161                                                     e.printStackTrace();
00162                                                 } 
00163                                                 }
00164 //                                              else
00165 //                                                      System.out.println("Launch of the dynamic view error! Select the octave editor.");
00166                                                 }
00167                          }); 
00168                  }
00169                         }
00170 
00171                         @Override
00172                         public void partBroughtToTop(IWorkbenchPart part) {
00173 
00174                         }
00175 
00176                         @Override
00177                         public void partClosed(IWorkbenchPart part) {
00178 
00179                         }
00180 
00181                         @Override
00182                         public void partDeactivated(IWorkbenchPart part) {
00183 
00184                         }
00185 
00186                         @Override
00187                         public void partOpened(IWorkbenchPart part) {
00188                                 
00189                         }
00190                         
00191                 });
00192         }
00193 
00197         public void setFocus() {
00198                 list.setFocus();
00199         }
00200 }
 All Classes Namespaces Files Functions Variables Enumerations