1 package com.bull.eclipse.jonas; 2 3 7 8 import java.util.ArrayList ; 9 10 import org.eclipse.core.resources.IResource; 11 import org.eclipse.core.runtime.CoreException; 12 import org.eclipse.core.runtime.IPath; 13 import org.eclipse.jdt.core.IClasspathEntry; 14 import org.eclipse.jdt.core.IJavaProject; 15 import org.eclipse.jdt.core.JavaModelException; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.layout.GridLayout; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.List; 21 22 import com.bull.eclipse.jonas.editors.ClasspathFieldEditor; 23 24 33 34 public class JonasProjectExtraResourcesPropertyPage { 35 private static final String WEBAPP_EXTRA_RESOURCES_FILENAME = ".extraresources"; 36 private static final String EXTRA_RESOURCES_CLASSPATH = "extraResources"; 37 38 private ClasspathFieldEditor erList; 39 private ExtraResourcesEntries entries; 40 private Composite group; 41 42 private JonasProjectPropertyPage page; 43 44 45 public JonasProjectExtraResourcesPropertyPage(JonasProjectPropertyPage page) { 46 this.page = page; 47 } 48 49 public IJavaProject getJavaProject() { 50 try { 51 return page.getJavaProject(); 52 } catch (CoreException e) { 53 JonasLauncherPlugin.log(e); 54 return null; 55 } 56 } 57 58 59 public boolean performOk() { 60 List newSelection = erList.getListControl(group); 61 62 try { 63 page.getJonasProject().setExtraResourcesEntries(new ExtraResourcesEntries(newSelection.getItems(),newSelection.getItemCount())); 64 page.getJonasProject().saveProperties(); 65 } catch(Exception ex) { 66 JonasLauncherPlugin.log(ex); 67 return false; 68 } 69 70 71 return true; 72 } 73 74 public Control getControl(Composite ctrl) { 75 group = new Composite(ctrl, SWT.NONE); 76 GridLayout layout = new GridLayout(); 77 layout.numColumns = 2; 78 group.setLayout(layout); 79 java.util.List listExRes = readSelectedEntries(); 80 if (listExRes != null) 81 erList = new ClasspathFieldEditor( 82 JonasLauncherPlugin.JONAS_EXTRA_RESOURCES_KEY, 83 JonasPluginResources.JONAS_EXTRA_RESOURCES_LABEL, 84 group, 85 listExRes); 86 else 87 erList = new ClasspathFieldEditor( 88 JonasLauncherPlugin.JONAS_EXTRA_RESOURCES_KEY, 89 JonasPluginResources.JONAS_EXTRA_RESOURCES_LABEL, 90 group); 91 92 erList.load(); 93 return group; 94 95 } 96 97 public void getExtraResourcesEntries(IJavaProject prj, ArrayList data) { 98 99 IClasspathEntry[] entries = null; 100 101 try { 102 add(data, prj.getProject().getWorkspace().getRoot().findMember(prj.getOutputLocation())); 103 entries = prj.getResolvedClasspath(false); 104 } catch(JavaModelException e) { 105 JonasLauncherPlugin.log(e); 106 } 107 if (entries == null) return; 108 for (int i = 0; i < entries.length; i++) { 109 IClasspathEntry entry = entries[i]; 110 if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { 111 String prjName = entry.getPath().lastSegment(); 112 getExtraResourcesEntries(getJavaProject().getJavaModel().getJavaProject(prjName), data); 113 } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { 114 IResource res = prj.getProject().getWorkspace().getRoot().findMember(entry.getPath()); 115 if (res != null) 116 add(data, res); 117 else 118 add(data, entry.getPath()); 119 } else if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { 120 add(data, entry.getPath()); 121 } 122 } 123 } 124 125 private void add(ArrayList data, IPath entry) { 126 if (entry.isAbsolute() == false) entry = entry.makeAbsolute(); 127 if (!data.contains(entry.toFile().toString())) { 128 data.add(entry.toFile().toString()); 129 } 130 } 131 private void add(ArrayList data, IResource con) { 132 if (con == null) return; 133 add(data, con.getLocation()); 134 } 135 136 137 private java.util.List readSelectedEntries() { 138 139 java.util.List listExtraRes = null; 140 try { 141 ExtraResourcesEntries exResEntr = page.getJonasProject().getExtraResourcesEntries(); 142 if (exResEntr != null) 143 listExtraRes = exResEntr.getList(); 144 } catch(Exception ex) { 145 JonasLauncherPlugin.log(ex); 146 } 147 return listExtraRes; 148 } 149 150 } 151 | Popular Tags |