1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: OntoText Lab. / SIRMA </p>
23 */
24
25
26 package org.wsmostudio.repository.ui.wizards;
27
28 import java.util.ArrayList;
29 import java.util.Iterator;
30 import java.util.List;
31
32 import org.eclipse.core.resources.IContainer;
33 import org.eclipse.core.resources.IFile;
34 import org.eclipse.core.resources.IProject;
35 import org.eclipse.core.resources.IResource;
36 import org.eclipse.core.resources.ResourcesPlugin;
37 import org.eclipse.core.runtime.CoreException;
38 import org.eclipse.jface.wizard.WizardPage;
39 import org.eclipse.swt.widgets.Composite;
40
41 import org.eclipse.jface.resource.JFaceResources;
42 import org.eclipse.jface.viewers.ISelectionChangedListener;
43 import org.eclipse.jface.viewers.IStructuredSelection;
44 import org.eclipse.jface.viewers.SelectionChangedEvent;
45 import org.eclipse.jface.viewers.TreeViewer;
46 import org.eclipse.swt.SWT;
47 import org.eclipse.swt.graphics.Image;
48 import org.eclipse.swt.layout.GridData;
49 import org.eclipse.swt.layout.GridLayout;
50 import org.eclipse.ui.model.WorkbenchContentProvider;
51 import org.eclipse.ui.model.WorkbenchLabelProvider;
52 import org.wsmostudio.runtime.WsmoImageRegistry;
53
54 /***
55 * The main export wizard page. It configures the UI layout and supplies
56 * specific information like labels, title, logo.
57 *
58 * @author not attributable
59 * @version $Revision: 469 $ $Date: 2006-01-09 14:51:14 +0200 $
60 */
61
62 public class ExportEntitiesWizardPage extends WizardPage {
63
64
65 Composite mainPanel;
66 private TreeViewer viewer;
67
68 public ExportEntitiesWizardPage(IStructuredSelection sel) {
69 super("Select WSML resources");
70 }
71
72 public boolean canFlipToNextPage() {
73 return false;
74 }
75
76 public String getName() {
77 return "Import WSMO Resources in Repository";
78 }
79
80 public boolean isPageComplete() {
81 IStructuredSelection sel = (IStructuredSelection)viewer.getSelection();
82 for(Iterator it = sel.iterator(); it.hasNext();) {
83 Object selObj = it.next();
84 if (false == selObj instanceof IFile
85 || false == ((IFile)selObj).getName().toLowerCase().endsWith(".wsml")) {
86 return false;
87 }
88 }
89 return true;
90 }
91
92 public IStructuredSelection getFileSelection() {
93 return (IStructuredSelection)viewer.getSelection();
94 }
95
96 public void createControl(Composite parent) {
97 mainPanel = new Composite(parent, SWT.NONE);
98 mainPanel.setLayout(new GridLayout(1, false));
99
100 viewer = new TreeViewer(mainPanel, SWT.BORDER | SWT.MULTI);
101 viewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
102 viewer.setContentProvider(new WorkbenchContentProvider() {
103 public Object[] getChildren(Object o) {
104 if (o instanceof IContainer) {
105 IResource[] members = null;
106 try {
107 members = ((IContainer) o).members();
108 }
109 catch (CoreException e) {
110 return new Object[0];
111 }
112 List<IResource> tempList = new ArrayList<IResource>();
113 for (int i = 0; i < members.length; i++) {
114 if (members[i] instanceof IFile
115 && false == ((IFile)members[i]).getName().toLowerCase().endsWith(".wsml")) {
116 continue;
117 }
118 tempList.add(members[i]);
119 }
120 return tempList.toArray();
121 }
122 else {
123 if (o instanceof ArrayList) {
124 return ((ArrayList) o).toArray();
125 }
126 else {
127 return new Object[0];
128 }
129 }
130 }
131 });
132 viewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
133
134 List<IProject> input = new ArrayList<IProject>();
135 IProject[] projects =
136 ResourcesPlugin.getWorkspace().getRoot().getProjects();
137 for (int i = 0; i < projects.length; i++) {
138 if (projects[i].isOpen())
139 input.add(projects[i]);
140 }
141 viewer.setInput(input);
142 viewer.addSelectionChangedListener(new ISelectionChangedListener() {
143 public void selectionChanged(SelectionChangedEvent e) {
144 getWizard().getContainer().updateButtons();
145 }
146 });
147 setControl(mainPanel);
148 }
149
150 public void dispose() {
151 mainPanel.dispose();
152 super.dispose();
153 }
154
155
156 public Image getImage() {
157 return JFaceResources.getImageRegistry().get(WsmoImageRegistry.WSMO_LOGO_SMALL);
158
159 }
160
161 public String getMessage() {
162 return "Select WSML source file(s) to import in repository";
163 }
164 }
165
166
167
168
169
170
171
172
173
174
175
176
177
178