Lines 36-52
Link Here
|
36 |
import javax.xml.transform.dom.DOMSource; |
36 |
import javax.xml.transform.dom.DOMSource; |
37 |
import javax.xml.transform.stream.StreamResult; |
37 |
import javax.xml.transform.stream.StreamResult; |
38 |
|
38 |
|
39 |
import org.w3c.dom.Document; |
|
|
40 |
import org.w3c.dom.Element; |
41 |
import org.w3c.dom.Node; |
42 |
import org.w3c.dom.NodeList; |
43 |
import org.xml.sax.InputSource; |
44 |
import org.xml.sax.SAXException; |
45 |
|
46 |
import org.eclipse.core.resources.IProject; |
47 |
import org.eclipse.core.resources.IResource; |
48 |
import org.eclipse.core.resources.IWorkspaceRoot; |
49 |
import org.eclipse.core.resources.ResourcesPlugin; |
50 |
import org.eclipse.core.runtime.CoreException; |
39 |
import org.eclipse.core.runtime.CoreException; |
51 |
import org.eclipse.core.runtime.IPath; |
40 |
import org.eclipse.core.runtime.IPath; |
52 |
import org.eclipse.core.runtime.IProgressMonitor; |
41 |
import org.eclipse.core.runtime.IProgressMonitor; |
Lines 55-60
Link Here
|
55 |
import org.eclipse.core.runtime.NullProgressMonitor; |
44 |
import org.eclipse.core.runtime.NullProgressMonitor; |
56 |
import org.eclipse.core.runtime.Path; |
45 |
import org.eclipse.core.runtime.Path; |
57 |
|
46 |
|
|
|
47 |
import org.eclipse.core.resources.IProject; |
48 |
import org.eclipse.core.resources.IResource; |
49 |
import org.eclipse.core.resources.IWorkspaceRoot; |
50 |
import org.eclipse.core.resources.ResourcesPlugin; |
51 |
|
58 |
import org.eclipse.swt.SWT; |
52 |
import org.eclipse.swt.SWT; |
59 |
import org.eclipse.swt.events.KeyEvent; |
53 |
import org.eclipse.swt.events.KeyEvent; |
60 |
import org.eclipse.swt.graphics.Point; |
54 |
import org.eclipse.swt.graphics.Point; |
Lines 102-108
Link Here
|
102 |
import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElementSorter; |
96 |
import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListElementSorter; |
103 |
import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListLabelProvider; |
97 |
import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPListLabelProvider; |
104 |
import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPUserLibraryElement; |
98 |
import org.eclipse.jdt.internal.ui.wizards.buildpaths.CPUserLibraryElement; |
105 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.*; |
99 |
import org.eclipse.jdt.internal.ui.wizards.buildpaths.NewVariableEntryDialog; |
|
|
100 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.CheckedListDialogField; |
101 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; |
102 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener; |
103 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter; |
104 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter; |
105 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.ITreeListAdapter; |
106 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil; |
107 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField; |
108 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField; |
109 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField; |
110 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField; |
111 |
import org.eclipse.jdt.internal.ui.wizards.dialogfields.TreeListDialogField; |
112 |
|
113 |
import org.w3c.dom.Document; |
114 |
import org.w3c.dom.Element; |
115 |
import org.w3c.dom.Node; |
116 |
import org.w3c.dom.NodeList; |
117 |
import org.xml.sax.InputSource; |
118 |
import org.xml.sax.SAXException; |
106 |
|
119 |
|
107 |
public class UserLibraryPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { |
120 |
public class UserLibraryPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { |
108 |
|
121 |
|
Lines 203-209
Link Here
|
203 |
private static final String TAG_VERSION= "version"; //$NON-NLS-1$ |
216 |
private static final String TAG_VERSION= "version"; //$NON-NLS-1$ |
204 |
private static final String TAG_LIBRARY= "library"; //$NON-NLS-1$ |
217 |
private static final String TAG_LIBRARY= "library"; //$NON-NLS-1$ |
205 |
private static final String TAG_SOURCEATTACHMENT= "source"; //$NON-NLS-1$ |
218 |
private static final String TAG_SOURCEATTACHMENT= "source"; //$NON-NLS-1$ |
206 |
private static final String TAG_ARCHIVE_PATH= "path"; //$NON-NLS-1$ |
219 |
private static final String TAG_ARCHIVE_PATH= "path"; //$NON-NLS-1$ |
|
|
220 |
private static final String TAG_ARCHIVE_TYPE= "type"; //$NON-NLS-1$ |
221 |
private static final String TAG_TYPE_VAR= "var"; //$NON-NLS-1$ |
207 |
private static final String TAG_ARCHIVE= "archive"; //$NON-NLS-1$ |
222 |
private static final String TAG_ARCHIVE= "archive"; //$NON-NLS-1$ |
208 |
private static final String TAG_SYSTEMLIBRARY= "systemlibrary"; //$NON-NLS-1$ |
223 |
private static final String TAG_SYSTEMLIBRARY= "systemlibrary"; //$NON-NLS-1$ |
209 |
private static final String TAG_NAME= "name"; //$NON-NLS-1$ |
224 |
private static final String TAG_NAME= "name"; //$NON-NLS-1$ |
Lines 528-534
Link Here
|
528 |
|
543 |
|
529 |
Element childElement= document.createElement(TAG_ARCHIVE); |
544 |
Element childElement= document.createElement(TAG_ARCHIVE); |
530 |
libraryElement.appendChild(childElement); |
545 |
libraryElement.appendChild(childElement); |
531 |
|
546 |
|
|
|
547 |
if (child.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { |
548 |
childElement.setAttribute(TAG_ARCHIVE_TYPE, TAG_TYPE_VAR); |
549 |
} |
532 |
childElement.setAttribute(TAG_ARCHIVE_PATH, child.getPath().toPortableString()); |
550 |
childElement.setAttribute(TAG_ARCHIVE_PATH, child.getPath().toPortableString()); |
533 |
IPath sourceAttachment= (IPath) child.getAttribute(CPListElement.SOURCEATTACHMENT); |
551 |
IPath sourceAttachment= (IPath) child.getAttribute(CPListElement.SOURCEATTACHMENT); |
534 |
if (sourceAttachment != null) { |
552 |
if (sourceAttachment != null) { |
Lines 609-616
Link Here
|
609 |
} |
627 |
} |
610 |
Element archiveElement= (Element) archiveNode; |
628 |
Element archiveElement= (Element) archiveNode; |
611 |
|
629 |
|
|
|
630 |
String type = archiveElement.getAttribute(TAG_ARCHIVE_TYPE); |
631 |
int cetype = IClasspathEntry.CPE_LIBRARY; |
632 |
if (TAG_TYPE_VAR.equals(type)) |
633 |
{ |
634 |
cetype = IClasspathEntry.CPE_VARIABLE; |
635 |
} |
612 |
String path= archiveElement.getAttribute(TAG_ARCHIVE_PATH); |
636 |
String path= archiveElement.getAttribute(TAG_ARCHIVE_PATH); |
613 |
CPListElement newArchive= new CPListElement(newLibrary, null, IClasspathEntry.CPE_LIBRARY, Path.fromPortableString(path), null); |
637 |
CPListElement newArchive= new CPListElement(newLibrary, null, cetype, Path.fromPortableString(path), null); |
614 |
newLibrary.add(newArchive); |
638 |
newLibrary.add(newArchive); |
615 |
|
639 |
|
616 |
if (archiveElement.hasAttribute(TAG_SOURCEATTACHMENT)) { |
640 |
if (archiveElement.hasAttribute(TAG_SOURCEATTACHMENT)) { |
Lines 637-646
Link Here
|
637 |
|
661 |
|
638 |
private static final int IDX_NEW= 0; |
662 |
private static final int IDX_NEW= 0; |
639 |
private static final int IDX_EDIT= 1; |
663 |
private static final int IDX_EDIT= 1; |
640 |
private static final int IDX_ADD= 2; |
664 |
private static final int IDX_ADD= 2; |
641 |
private static final int IDX_REMOVE= 3; |
665 |
private static final int IDX_ADDVAR= 3; |
642 |
private static final int IDX_LOAD= 5; |
666 |
private static final int IDX_REMOVE= 4; |
643 |
private static final int IDX_SAVE= 6; |
667 |
private static final int IDX_LOAD= 6; |
|
|
668 |
private static final int IDX_SAVE= 7; |
644 |
|
669 |
|
645 |
/** |
670 |
/** |
646 |
* Constructor for ClasspathVariablesPreferencePage |
671 |
* Constructor for ClasspathVariablesPreferencePage |
Lines 660-666
Link Here
|
660 |
String[] buttonLabels= new String[] { |
685 |
String[] buttonLabels= new String[] { |
661 |
PreferencesMessages.getString("UserLibraryPreferencePage.libraries.new.button"), //$NON-NLS-1$ |
686 |
PreferencesMessages.getString("UserLibraryPreferencePage.libraries.new.button"), //$NON-NLS-1$ |
662 |
PreferencesMessages.getString("UserLibraryPreferencePage.libraries.edit.button"), //$NON-NLS-1$ |
687 |
PreferencesMessages.getString("UserLibraryPreferencePage.libraries.edit.button"), //$NON-NLS-1$ |
663 |
PreferencesMessages.getString("UserLibraryPreferencePage.libraries.addjar.button"), //$NON-NLS-1$ |
688 |
PreferencesMessages.getString("UserLibraryPreferencePage.libraries.addjar.button"), //$NON-NLS-1$ |
|
|
689 |
PreferencesMessages.getString("UserLibraryPreferencePage.libraries.addvar.button"), //$NON-NLS-1$ |
664 |
PreferencesMessages.getString("UserLibraryPreferencePage.libraries.remove.button"), //$NON-NLS-1$ |
690 |
PreferencesMessages.getString("UserLibraryPreferencePage.libraries.remove.button"), //$NON-NLS-1$ |
665 |
null, |
691 |
null, |
666 |
PreferencesMessages.getString("UserLibraryPreferencePage.libraries.load.button"), //$NON-NLS-1$ |
692 |
PreferencesMessages.getString("UserLibraryPreferencePage.libraries.load.button"), //$NON-NLS-1$ |
Lines 900-914
Link Here
|
900 |
List list= field.getSelectedElements(); |
926 |
List list= field.getSelectedElements(); |
901 |
field.enableButton(IDX_REMOVE, canRemove(list)); |
927 |
field.enableButton(IDX_REMOVE, canRemove(list)); |
902 |
field.enableButton(IDX_EDIT, canEdit(list)); |
928 |
field.enableButton(IDX_EDIT, canEdit(list)); |
903 |
field.enableButton(IDX_ADD, canAdd(list)); |
929 |
field.enableButton(IDX_ADD, canAdd(list)); |
|
|
930 |
field.enableButton(IDX_ADDVAR, canAdd(list)); |
904 |
field.enableButton(IDX_SAVE, field.getSize() > 0); |
931 |
field.enableButton(IDX_SAVE, field.getSize() > 0); |
905 |
} |
932 |
} |
906 |
|
933 |
|
907 |
protected void doCustomButtonPressed(TreeListDialogField field, int index) { |
934 |
protected void doCustomButtonPressed(TreeListDialogField field, int index) { |
908 |
if (index == IDX_NEW) { |
935 |
if (index == IDX_NEW) { |
909 |
editUserLibraryElement(null); |
936 |
editUserLibraryElement(null); |
910 |
} else if (index == IDX_ADD) { |
937 |
} else if (index == IDX_ADD) { |
911 |
doAdd(field.getSelectedElements()); |
938 |
doAdd(field.getSelectedElements()); |
|
|
939 |
} else if (index == IDX_ADDVAR) { |
940 |
doAddVar(field.getSelectedElements()); |
912 |
} else if (index == IDX_REMOVE) { |
941 |
} else if (index == IDX_REMOVE) { |
913 |
doRemove(field.getSelectedElements()); |
942 |
doRemove(field.getSelectedElements()); |
914 |
} else if (index == IDX_EDIT) { |
943 |
} else if (index == IDX_EDIT) { |
Lines 944-951
Link Here
|
944 |
} else if (curr instanceof CPUserLibraryElement) { |
973 |
} else if (curr instanceof CPUserLibraryElement) { |
945 |
editUserLibraryElement((CPUserLibraryElement) curr); |
974 |
editUserLibraryElement((CPUserLibraryElement) curr); |
946 |
} else if (curr instanceof CPListElement) { |
975 |
} else if (curr instanceof CPListElement) { |
947 |
CPListElement elem= (CPListElement) curr; |
976 |
CPListElement elem= (CPListElement) curr; |
948 |
editArchiveElement(elem, (CPUserLibraryElement) elem.getParentContainer()); |
977 |
if (elem.getEntryKind() == IClasspathEntry.CPE_VARIABLE) |
|
|
978 |
{ |
979 |
editVariableElement(elem, (CPUserLibraryElement) elem.getParentContainer()); |
980 |
} |
981 |
else |
982 |
{ |
983 |
editArchiveElement(elem, (CPUserLibraryElement) elem.getParentContainer()); |
984 |
} |
949 |
} |
985 |
} |
950 |
} |
986 |
} |
951 |
} |
987 |
} |
Lines 964-985
Link Here
|
964 |
} |
1000 |
} |
965 |
} |
1001 |
} |
966 |
|
1002 |
|
967 |
private void editArchiveElement(CPListElement existingElement, CPUserLibraryElement parent) { |
1003 |
private void editArchiveElement(CPListElement existingElement, CPUserLibraryElement parent) { |
968 |
CPListElement[] elements= openExtJarFileDialog(existingElement, parent); |
1004 |
CPListElement[] elements= openExtJarFileDialog(existingElement, parent); |
969 |
if (elements != null) { |
1005 |
if (elements != null) { |
970 |
for (int i= 0; i < elements.length; i++) { |
1006 |
for (int i= 0; i < elements.length; i++) { |
971 |
if (existingElement != null) { |
1007 |
if (existingElement != null) { |
972 |
parent.replace(existingElement, elements[i]); |
1008 |
parent.replace(existingElement, elements[i]); |
973 |
} else { |
1009 |
} else { |
974 |
parent.add(elements[i]); |
1010 |
parent.add(elements[i]); |
975 |
} |
1011 |
} |
976 |
} |
1012 |
} |
977 |
fLibraryList.refresh(parent); |
1013 |
fLibraryList.refresh(parent); |
978 |
fLibraryList.expandElement(parent, AbstractTreeViewer.ALL_LEVELS); |
1014 |
fLibraryList.expandElement(parent, AbstractTreeViewer.ALL_LEVELS); |
979 |
fLibraryList.selectElements(new StructuredSelection(parent)); |
1015 |
fLibraryList.selectElements(new StructuredSelection(parent)); |
980 |
} |
1016 |
} |
981 |
} |
1017 |
} |
982 |
|
1018 |
|
|
|
1019 |
private void editVariableElement(CPListElement existingElement, CPUserLibraryElement parent) { |
1020 |
CPListElement[] elements= openVariableDialog(existingElement, parent); |
1021 |
if (elements != null) { |
1022 |
for (int i= 0; i < elements.length; i++) { |
1023 |
if (existingElement != null) { |
1024 |
parent.replace(existingElement, elements[i]); |
1025 |
} else { |
1026 |
parent.add(elements[i]); |
1027 |
} |
1028 |
} |
1029 |
fLibraryList.refresh(parent); |
1030 |
fLibraryList.expandElement(parent, AbstractTreeViewer.ALL_LEVELS); |
1031 |
fLibraryList.selectElements(new StructuredSelection(parent)); |
1032 |
} |
1033 |
} |
1034 |
|
1035 |
private CPListElement[] openVariableDialog(CPListElement existing, Object parent) { |
1036 |
NewVariableEntryDialog dialog= new NewVariableEntryDialog(getShell(), true); |
1037 |
if (dialog.open() != Window.OK) { |
1038 |
return null; |
1039 |
} |
1040 |
|
1041 |
IPath[] varPaths = dialog.getResult(); |
1042 |
CPListElement[] elems= new CPListElement[varPaths.length]; |
1043 |
for (int i= 0; i < varPaths.length; i++) { |
1044 |
CPListElement curr= new CPListElement(parent, null, IClasspathEntry.CPE_VARIABLE, varPaths[i], null); |
1045 |
curr.setAttribute(CPListElement.SOURCEATTACHMENT, BuildPathSupport.guessSourceAttachment(curr)); |
1046 |
curr.setAttribute(CPListElement.JAVADOC, BuildPathSupport.guessJavadocLocation(curr)); |
1047 |
elems[i]= curr; |
1048 |
} |
1049 |
return elems; |
1050 |
} |
983 |
|
1051 |
|
984 |
private void doRemove(List selected) { |
1052 |
private void doRemove(List selected) { |
985 |
Object selectionAfter= null; |
1053 |
Object selectionAfter= null; |
Lines 1010-1022
Link Here
|
1010 |
} |
1078 |
} |
1011 |
} |
1079 |
} |
1012 |
|
1080 |
|
1013 |
private void doAdd(List list) { |
1081 |
private void doAdd(List list) { |
1014 |
if (canAdd(list)) { |
1082 |
if (canAdd(list)) { |
1015 |
CPUserLibraryElement element= getSingleSelectedLibrary(list); |
1083 |
CPUserLibraryElement element= getSingleSelectedLibrary(list); |
1016 |
editArchiveElement(null, element); |
1084 |
editArchiveElement(null, element); |
1017 |
} |
1085 |
} |
1018 |
} |
1086 |
} |
1019 |
|
1087 |
|
|
|
1088 |
private void doAddVar(List list) { |
1089 |
if (canAdd(list)) { |
1090 |
CPUserLibraryElement element= getSingleSelectedLibrary(list); |
1091 |
editVariableElement(null, element); |
1092 |
} |
1093 |
} |
1094 |
|
1020 |
private void doLoad() { |
1095 |
private void doLoad() { |
1021 |
List existing= fLibraryList.getElements(); |
1096 |
List existing= fLibraryList.getElements(); |
1022 |
LoadSaveDialog dialog= new LoadSaveDialog(getShell(), false, existing, fDialogSettings); |
1097 |
LoadSaveDialog dialog= new LoadSaveDialog(getShell(), false, existing, fDialogSettings); |