KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > utils > UtilServicesClass


1 /*
2  * Created on 9 mars 2004
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package com.bull.eclipse.jonas.utils;
8
9 import java.lang.reflect.InvocationTargetException JavaDoc;
10 import java.util.Vector JavaDoc;
11
12 import org.eclipse.core.runtime.IProgressMonitor;
13 import org.eclipse.core.runtime.NullProgressMonitor;
14 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
15 import org.eclipse.jface.operation.IRunnableWithProgress;
16 import org.eclipse.jface.viewers.IStructuredContentProvider;
17 import org.eclipse.jface.viewers.LabelProvider;
18 import org.eclipse.jface.viewers.Viewer;
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.IWorkbenchPage;
21 import org.eclipse.ui.IWorkbenchWindow;
22 import org.eclipse.ui.PlatformUI;
23 import org.eclipse.ui.dialogs.ListSelectionDialog;
24 import org.eclipse.ui.part.FileEditorInput;
25
26 import com.bull.eclipse.jonas.JonasPluginResources;
27
28 /**
29  * @author cnedi
30  *
31  * To change the template for this generated type comment go to
32  * Window>Preferences>Java>Code Generation>Code and Comments
33  */

34 public class UtilServicesClass {
35
36     public static void saveFiles() {
37
38         IWorkbenchWindow[] wk = PlatformUI.getWorkbench().getWorkbenchWindows();
39         IWorkbenchPage[] wp = wk[0].getPages();
40         final IEditorPart ep[] = wp[0].getDirtyEditors();
41         final String JavaDoc[] szFiles = new String JavaDoc[ep.length];
42         // is there any file to save ?
43
if (ep.length == 0)
44             return;
45
46         for (int u = 0; u < ep.length; u++) {
47             szFiles[u] =
48                 ((FileEditorInput) ep[u].getEditorInput())
49                     .getFile()
50                     .getFullPath()
51                     .toString();
52
53         }
54
55         ListSelectionDialog dlg =
56             new ListSelectionDialog(
57                 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
58                 new Object JavaDoc(),
59                 new IStructuredContentProvider() {
60
61             public void dispose() {
62             }
63
64             public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
65                 return szFiles;
66             }
67
68             public void inputChanged(Viewer viewer1, Object JavaDoc obj, Object JavaDoc obj1) {
69             }
70
71         }, new LabelProvider(), "Select the files.");
72
73         dlg.setTitle("Save Files pending updates");
74         dlg.open();
75         final Object JavaDoc results_upd[] = dlg.getResult();
76
77         final Vector JavaDoc IEditorParttoSave = new Vector JavaDoc(10);
78
79         if (results_upd != null && results_upd.length > 0) {
80             for (int i = 0; i < results_upd.length; i++) {
81                 System.out.println(" File to save ..." + results_upd[i]);
82                 for (int v = 0; v < szFiles.length; v++) {
83                     if (results_upd[i].equals(szFiles[v])) {
84
85                         IEditorParttoSave.add(ep[v]);
86                         break;
87                     }
88
89                 }
90
91             }
92         }
93         IRunnableWithProgress worker = new IRunnableWithProgress() {
94             public void run(IProgressMonitor monitor)
95                 throws InvocationTargetException JavaDoc {
96                 try {
97
98                     monitor.setTaskName(
99                         JonasPluginResources.GEN_INTERFACES_TITLE);
100
101                     // local/remote
102
monitor.beginTask(
103                         JonasPluginResources.GEN_INTERFACES_MSG_LOCAL,
104                         IEditorParttoSave.size());
105
106                     for (int i = 0; i < IEditorParttoSave.size(); i++) {
107                         IEditorPart ip =
108                             (IEditorPart) IEditorParttoSave.elementAt(i);
109                         monitor.setTaskName(
110                             " Saving ..."
111                                 + ((FileEditorInput) ip.getEditorInput())
112                                     .getFile()
113                                     .getFullPath()
114                                     .toString());
115                         ip.doSave(new NullProgressMonitor());
116                         monitor.worked(i + 1);
117                     }
118                 } catch (Exception JavaDoc e) {
119                 } finally {
120                     monitor.done();
121                 }
122             }
123         };
124         /***
125          * Run worker thread
126          */

127         try {
128             new ProgressMonitorDialog(
129                 PlatformUI
130                     .getWorkbench()
131                     .getActiveWorkbenchWindow()
132                     .getShell())
133                     .run(
134                 false,
135                 false,
136                 worker);
137         } catch (InterruptedException JavaDoc e) {
138             e.printStackTrace();
139         } catch (InvocationTargetException JavaDoc e) {
140             e.printStackTrace();
141         }
142     }
143
144 }
145
Popular Tags