1 package com.bull.eclipse.jonas.editors; 2 3 7 8 13 14 import java.io.File ; 15 import java.util.List ; 16 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.events.SelectionAdapter; 19 import org.eclipse.swt.events.SelectionEvent; 20 import org.eclipse.swt.widgets.Button; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.DirectoryDialog; 23 import org.eclipse.swt.widgets.FileDialog; 24 import org.eclipse.swt.widgets.Widget; 25 26 import com.bull.eclipse.jonas.JonasPluginResources; 27 28 31 public class ClasspathFieldEditor extends ListFieldEditor implements JonasPluginResources { 32 33 protected Button addJarZipButton; 34 protected Button addDirButton; 35 36 39 private String lastPath; 40 41 44 protected ClasspathFieldEditor() { 45 } 46 47 48 public ClasspathFieldEditor(String name, String labelText, Composite parent) { 49 init(name, labelText); 50 createControl(parent); 51 } 52 53 public ClasspathFieldEditor(String name, String labelText, Composite parent, List extraList) { 54 init(name, labelText); 55 createControl(parent); 56 convertutilListtoWidgetList(extraList); 57 } 59 60 protected String [] getNewJarZip() { 61 FileDialog dialog = new FileDialog(addJarZipButton.getShell(), SWT.MULTI); 62 if (lastPath != null) { 63 if (new File (lastPath).exists()) 64 dialog.setFilterPath(lastPath); 65 } 66 String file = dialog.open(); 67 68 if (dialog.getFileNames().length != 0) { 69 lastPath = dialog.getFilterPath(); 70 String [] result = dialog.getFileNames(); 71 for (int i = 0; i < result.length; i++) { 72 result[i] = lastPath + File.separator + result[i]; 73 } 74 return result; 75 } else { 76 return new String [0]; 77 } 78 } 79 80 protected String getNewDir() { 81 DirectoryDialog dialog = new DirectoryDialog(addDirButton.getShell()); 82 if (lastPath != null) { 83 if (new File (lastPath).exists()) 84 dialog.setFilterPath(lastPath); 85 } 86 String dir = dialog.open(); 87 if (dir != null) { 88 dir = dir.trim(); 89 if (dir.length() == 0) 90 return null; 91 lastPath = dir; 92 } 93 return dir; 94 } 95 96 protected void createButtons(Composite buttonBox) { 97 addJarZipButton = createPushButton(buttonBox, PREF_PAGE_ADDJARZIPBUTTON_LABEL); addDirButton = createPushButton(buttonBox, PREF_PAGE_ADDDIRBUTTON_LABEL); removeButton = createPushButton(buttonBox, PREF_PAGE_REMOVEBUTTON_LABEL); upButton = createPushButton(buttonBox, PREF_PAGE_UPBUTTON_LABEL); downButton = createPushButton(buttonBox, PREF_PAGE_DOWNBUTTON_LABEL); } 103 104 107 public void createSelectionListener() { 108 selectionListener = new SelectionAdapter() { 109 public void widgetSelected(SelectionEvent event) { 110 Widget widget = event.widget; 111 if (widget == addJarZipButton) { 112 addJarZipPressed(); 113 } else 114 if (widget == addDirButton) { 115 addDirPressed(); 116 } else 117 if (widget == removeButton) { 118 removePressed(); 119 } else 120 if (widget == upButton) { 121 upPressed(); 122 } else 123 if (widget == downButton) { 124 downPressed(); 125 } else 126 if (widget == list) { 127 selectionChanged(); 128 } 129 } 130 }; 131 } 132 133 protected void addJarZipPressed() { 134 setPresentsDefaultValue(false); 135 String [] input = getNewJarZip(); 136 137 for(int i=0; i<input.length; i++) { 138 if (input != null) { 139 int index = list.getSelectionIndex(); 140 if (index >= 0) 141 list.add(input[i], index + 1); 142 else 143 list.add(input[i], 0); 144 selectionChanged(); 145 } 146 } 147 } 148 149 150 protected void addDirPressed() { 151 setPresentsDefaultValue(false); 152 String input = getNewDir(); 153 154 if (input != null) { 155 int index = list.getSelectionIndex(); 156 if (index >= 0) 157 list.add(input, index + 1); 158 else 159 list.add(input, 0); 160 selectionChanged(); 161 } 162 } 163 164 protected void convertutilListtoWidgetList(java.util.List extraList) { 165 int i = 0; 166 while (i < extraList.size()) { 167 list.add((String )extraList.get(i)); 168 i++; 169 } 170 171 } 172 } | Popular Tags |