diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java index 7fe3af9..0b08028 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.java @@ -370,12 +370,12 @@ public static String SourceAttachmentBlock_message; public static String SourceAttachmentBlock_filename_description; - public static String SourceAttachmentBlock_filename_label; public static String SourceAttachmentBlock_filename_externalfile_button; public static String SourceAttachmentBlock_filename_externalfolder_button; public static String SourceAttachmentBlock_filename_internal_button; public static String SourceAttachmentBlock_filename_varlabel; public static String SourceAttachmentBlock_filename_variable_button; + public static String SourceAttachmentBlock_filename_external_label; public static String SourceAttachmentBlock_filename_external_varbutton; public static String SourceAttachmentBlock_filename_error_notvalid; public static String SourceAttachmentBlock_filename_error_notabsolute; @@ -383,8 +383,12 @@ public static String SourceAttachmentBlock_filename_error_varnotexists; public static String SourceAttachmentBlock_filename_error_deviceinpath; public static String SourceAttachmentBlock_filename_warning_varempty; + public static String SourceAttachmentBlock_filename_workspace_browse; + public static String SourceAttachmentBlock_filename_workspace_label; public static String SourceAttachmentBlock_intjardialog_title; public static String SourceAttachmentBlock_intjardialog_message; + public static String SourceAttachmentBlock_encoding_label; + public static String SourceAttachmentBlock_external_radiolabel; public static String SourceAttachmentBlock_extvardialog_title; public static String SourceAttachmentBlock_extvardialog_description; public static String SourceAttachmentBlock_extjardialog_text; @@ -701,6 +705,7 @@ public static String NativeLibrariesDialog_external_message; public static String SourceAttachmentBlock_extfolderdialog_message; + public static String SourceAttachmentBlock_workspace_radiolabel; public static String AccessRulesDialog_severity_info_with_link; public static String AccessRulesDialog_severity_info_no_link; public static String AccessRulesDialog_severity_error; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties index 4205d59..90392d1 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/NewWizardMessages.properties @@ -395,13 +395,14 @@ SourceAttachmentBlock_message=Select the location (folder, JAR or zip) containing the source for ''{0}'': SourceAttachmentBlock_filename_description=Source attachments for variable entries are defined by variable paths. The first segment of such a path describes a variable name, the rest is an optional path extension. -SourceAttachmentBlock_filename_label=Lo&cation path: +SourceAttachmentBlock_filename_external_label=Pa&th: SourceAttachmentBlock_filename_externalfile_button=External &File... SourceAttachmentBlock_filename_externalfolder_button=External F&older... SourceAttachmentBlock_filename_internal_button=&Workspace... SourceAttachmentBlock_filename_varlabel=Lo&cation variable path: SourceAttachmentBlock_filename_variable_button=&Variable... +SourceAttachmentBlock_external_radiolabel=E&xternal location SourceAttachmentBlock_filename_external_varbutton=&Extension.... SourceAttachmentBlock_filename_error_notvalid= The archive path is not a valid path. @@ -410,16 +411,20 @@ SourceAttachmentBlock_filename_error_varnotexists= The variable in the location variable path does not exist. SourceAttachmentBlock_filename_error_deviceinpath= The location variable path must begin with a variable. SourceAttachmentBlock_filename_warning_varempty= The location variable path is empty. +SourceAttachmentBlock_filename_workspace_browse=&Browse +SourceAttachmentBlock_filename_workspace_label=&Path: SourceAttachmentBlock_intjardialog_title=Source Location Selection SourceAttachmentBlock_intjardialog_message=&Select folder or JAR/zip archive containing the source: +SourceAttachmentBlock_encoding_label=E&ncoding: SourceAttachmentBlock_extvardialog_title=Variable Extension Selection SourceAttachmentBlock_extvardialog_description=Select source location: SourceAttachmentBlock_extjardialog_text=JAR/ZIP File Selection SourceAttachmentBlock_extfolderdialog_text=Folder Selection SourceAttachmentBlock_extfolderdialog_message=Choose a directory containing source: +SourceAttachmentBlock_workspace_radiolabel=Wor&kspace location BuildPathSupport_putoncpdialog_title=Setting Source Attachment BuildPathSupport_deprecated={0} is deprecated: {1}. diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/CPListElement.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/CPListElement.java index 9824b4c..fd0ef78 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/CPListElement.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/CPListElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -54,6 +54,7 @@ public static final String COMBINE_ACCESSRULES= "combineaccessrules"; //$NON-NLS-1$ public static final String JAVADOC= IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME; + public static final String SOURCE_ATTACHMENT_ENCODING= IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING; public static final String NATIVE_LIB_PATH= JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY; private IJavaProject fProject; @@ -118,6 +119,7 @@ case IClasspathEntry.CPE_VARIABLE: createAttributeElement(SOURCEATTACHMENT, null, true); createAttributeElement(JAVADOC, null, false); + createAttributeElement(SOURCE_ATTACHMENT_ENCODING, null, false); createAttributeElement(NATIVE_LIB_PATH, null, false); createAttributeElement(ACCESSRULES, new IAccessRule[0], true); break; diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/LibrariesWorkbookPage.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/LibrariesWorkbookPage.java index af78015..aec838f 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/LibrariesWorkbookPage.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/LibrariesWorkbookPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -488,7 +488,8 @@ IClasspathEntry result= BuildPathDialogAccess.configureSourceAttachment(getShell(), selElement.getClasspathEntry()); if (result != null) { selElement.setAttribute(CPListElement.SOURCEATTACHMENT, result.getSourceAttachmentPath()); - String[] changedAttributes= { CPListElement.SOURCEATTACHMENT }; + selElement.setAttribute(CPListElement.SOURCE_ATTACHMENT_ENCODING, SourceAttachmentBlock.getSourceAttachmentEncoding(result)); + String[] changedAttributes= { CPListElement.SOURCEATTACHMENT, CPListElement.SOURCE_ATTACHMENT_ENCODING }; attributeUpdated(selElement, changedAttributes); fLibrariesList.refresh(elem); fLibrariesList.update(selElement); // image diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/SourceAttachmentBlock.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/SourceAttachmentBlock.java index fc4b2e4..7a47f0d 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/SourceAttachmentBlock.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/SourceAttachmentBlock.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -32,6 +32,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; @@ -44,9 +45,11 @@ import org.eclipse.jface.window.Window; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDEEncoding; import org.eclipse.ui.model.WorkbenchContentProvider; import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.jdt.core.IClasspathAttribute; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; @@ -56,10 +59,10 @@ import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; import org.eclipse.jdt.internal.ui.JavaPlugin; import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; -import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels; import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener; import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; +import org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField; import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener; import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter; @@ -77,11 +80,16 @@ private final IStatusChangeListener fContext; - private StringButtonDialogField fFileNameField; - private SelectionButtonDialogField fWorkspaceButton; + private StringButtonDialogField fWorkspaceFileNameField; + private StringButtonDialogField fExternalFileNameField; + private StringButtonDialogField fVariableFileNameField; private SelectionButtonDialogField fExternalFolderButton; + private SelectionButtonDialogField fExternalRadio, fWorkspaceRadio; + private ComboDialogField fEncodingCombo; - private IStatus fNameStatus; + private IStatus fWorkspaceNameStatus; + private IStatus fExternalNameStatus; + private IStatus fVariableNameStatus; /** * The path to which the archive variable points. @@ -113,59 +121,104 @@ fWorkspaceRoot= ResourcesPlugin.getWorkspace().getRoot(); - fNameStatus= new StatusInfo(); + fWorkspaceNameStatus= new StatusInfo(); + fExternalNameStatus= new StatusInfo(); + fVariableNameStatus= new StatusInfo(); SourceAttachmentAdapter adapter= new SourceAttachmentAdapter(); // create the dialog fields (no widgets yet) if (isVariableEntry()) { - fFileNameField= new VariablePathDialogField(adapter); - fFileNameField.setDialogFieldListener(adapter); - fFileNameField.setLabelText(NewWizardMessages.SourceAttachmentBlock_filename_varlabel); - fFileNameField.setButtonLabel(NewWizardMessages.SourceAttachmentBlock_filename_external_varbutton); - ((VariablePathDialogField)fFileNameField).setVariableButtonLabel(NewWizardMessages.SourceAttachmentBlock_filename_variable_button); - + fVariableFileNameField= new VariablePathDialogField(adapter); + fVariableFileNameField.setDialogFieldListener(adapter); + fVariableFileNameField.setLabelText(NewWizardMessages.SourceAttachmentBlock_filename_varlabel); + fVariableFileNameField.setButtonLabel(NewWizardMessages.SourceAttachmentBlock_filename_external_varbutton); + ((VariablePathDialogField) fVariableFileNameField).setVariableButtonLabel(NewWizardMessages.SourceAttachmentBlock_filename_variable_button); } else { - fFileNameField= new StringButtonDialogField(adapter); - fFileNameField.setDialogFieldListener(adapter); - fFileNameField.setLabelText(NewWizardMessages.SourceAttachmentBlock_filename_label); - fFileNameField.setButtonLabel(NewWizardMessages.SourceAttachmentBlock_filename_externalfile_button); + fWorkspaceRadio= new SelectionButtonDialogField(SWT.RADIO); + fWorkspaceRadio.setDialogFieldListener(adapter); + fWorkspaceRadio.setLabelText(NewWizardMessages.SourceAttachmentBlock_workspace_radiolabel); - fWorkspaceButton= new SelectionButtonDialogField(SWT.PUSH); - fWorkspaceButton.setDialogFieldListener(adapter); - fWorkspaceButton.setLabelText(NewWizardMessages.SourceAttachmentBlock_filename_internal_button); + fWorkspaceFileNameField= new StringButtonDialogField(adapter); + fWorkspaceFileNameField.setDialogFieldListener(adapter); + fWorkspaceFileNameField.setLabelText(NewWizardMessages.SourceAttachmentBlock_filename_workspace_label); + fWorkspaceFileNameField.setButtonLabel(NewWizardMessages.SourceAttachmentBlock_filename_workspace_browse); + + fExternalRadio= new SelectionButtonDialogField(SWT.RADIO); + fExternalRadio.setDialogFieldListener(adapter); + fExternalRadio.setLabelText(NewWizardMessages.SourceAttachmentBlock_external_radiolabel); + + fExternalFileNameField= new StringButtonDialogField(adapter); + fExternalFileNameField.setDialogFieldListener(adapter); + fExternalFileNameField.setLabelText(NewWizardMessages.SourceAttachmentBlock_filename_external_label); + fExternalFileNameField.setButtonLabel(NewWizardMessages.SourceAttachmentBlock_filename_externalfile_button); fExternalFolderButton= new SelectionButtonDialogField(SWT.PUSH); fExternalFolderButton.setDialogFieldListener(adapter); fExternalFolderButton.setLabelText(NewWizardMessages.SourceAttachmentBlock_filename_externalfolder_button); } + fEncodingCombo= new ComboDialogField(SWT.DROP_DOWN); + fEncodingCombo.setDialogFieldListener(adapter); + fEncodingCombo.setLabelText(NewWizardMessages.SourceAttachmentBlock_encoding_label); + List encodings= IDEEncoding.getIDEEncodings(); + fEncodingCombo.setItems(encodings.toArray(new String[encodings.size()])); + // set the old settings setDefaults(); } public void setDefaults() { + String path= ""; //$NON-NLS-1$ + String encoding= null; + if (fEntry.getSourceAttachmentPath() != null) { - fFileNameField.setText(fEntry.getSourceAttachmentPath().toString()); - } else { - fFileNameField.setText(""); //$NON-NLS-1$ + path= fEntry.getSourceAttachmentPath().toString(); + encoding= getSourceAttachmentEncoding(fEntry); } + + if (encoding == null) { + encoding= ""; //$NON-NLS-1$ + } + + if (isVariableEntry()) { + fVariableFileNameField.setText(path); + fEncodingCombo.setText(encoding); + } else { + if (isWorkspacePath(path)) { + fWorkspaceRadio.setSelection(true); + fWorkspaceFileNameField.setText(path); + } else if (path.length() != 0) { + fExternalRadio.setSelection(true); + fExternalFileNameField.setText(path); + fEncodingCombo.setText(encoding); + } else { + fWorkspaceRadio.setSelection(true); + fExternalRadio.setSelection(false); + } + } + } + + private boolean isWorkspacePath(String path) { + IPath iPath= Path.fromOSString(path); + if (iPath == null || iPath.getDevice() != null) + return false; + IWorkspace workspace= ResourcesPlugin.getWorkspace(); + if (workspace == null) + return false; + return workspace.getRoot().findMember(iPath) != null; } private boolean isVariableEntry() { return fEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE; } - /** * Gets the source attachment path chosen by the user * @return the source attachment path */ public IPath getSourceAttachmentPath() { - if (fFileNameField.getText().length() == 0) { - return null; - } - return getFilePath(); + return (getFilePath().segmentCount() == 0) ? null : getFilePath(); } /** @@ -177,9 +230,18 @@ return null; } + private String getEncoding() { + if (isVariableEntry() || (fExternalRadio != null && fExternalRadio.isSelected())) { + String encoding= fEncodingCombo.getText(); + return (encoding == null || encoding.length() == 0) ? null : encoding; + } + return null; + } + public IClasspathEntry getNewEntry() { CPListElement elem= CPListElement.createFromExisting(fEntry, fProject); elem.setAttribute(CPListElement.SOURCEATTACHMENT, getSourceAttachmentPath()); + elem.setAttribute(CPListElement.SOURCE_ATTACHMENT_ENCODING, getEncoding()); return elem.getClasspathEntry(); } @@ -219,8 +281,8 @@ desc.setLayoutData(gd); desc.setText(NewWizardMessages.SourceAttachmentBlock_filename_description); - fFileNameField.doFillIntoGrid(composite, 4); - LayoutUtil.setWidthHint(fFileNameField.getTextControl(null), widthHint); + fVariableFileNameField.doFillIntoGrid(composite, 4); + LayoutUtil.setWidthHint(fVariableFileNameField.getTextControl(null), widthHint); // label that shows the resolved path for variable jars //DialogField.createEmptySpace(composite, 1); @@ -230,7 +292,9 @@ gd.widthHint= labelWidthHint; fFullPathResolvedLabel.setLayoutData(gd); - LayoutUtil.setHorizontalGrabbing(fFileNameField.getTextControl(null)); + DialogField.createEmptySpace(composite, 4); + + fEncodingCombo.doFillIntoGrid(composite, 2); } else { int widthHint= converter.convertWidthInCharsToPixels(60); @@ -241,22 +305,27 @@ message.setLayoutData(gd); message.setText(Messages.format(NewWizardMessages.SourceAttachmentBlock_message, BasicElementLabels.getResourceName(fEntry.getPath().lastSegment()))); - fWorkspaceButton.doFillIntoGrid(composite, 1); - ((GridData) fWorkspaceButton.getSelectionButton(null).getLayoutData()).verticalAlignment= SWT.END; + fWorkspaceRadio.doFillIntoGrid(composite, 4); + fWorkspaceFileNameField.doFillIntoGrid(composite, 4); + LayoutUtil.setWidthHint(fWorkspaceFileNameField.getTextControl(null), widthHint); + LayoutUtil.setHorizontalGrabbing(fWorkspaceFileNameField.getTextControl(null)); - // archive name field - fFileNameField.doFillIntoGrid(composite, 4); - LayoutUtil.setWidthHint(fFileNameField.getTextControl(null), widthHint); - LayoutUtil.setHorizontalGrabbing(fFileNameField.getTextControl(null)); + DialogField.createEmptySpace(composite, 4); - // Additional 'browse workspace' button for normal jars - DialogField.createEmptySpace(composite, 3); + fExternalRadio.doFillIntoGrid(composite, 4); + fExternalFileNameField.doFillIntoGrid(composite, 4); + LayoutUtil.setWidthHint(fExternalFileNameField.getTextControl(null), widthHint); + LayoutUtil.setHorizontalGrabbing(fExternalFileNameField.getTextControl(null)); + + fEncodingCombo.doFillIntoGrid(composite, 2); + DialogField.createEmptySpace(composite, 1); fExternalFolderButton.doFillIntoGrid(composite, 1); - } - fFileNameField.postSetFocusOnDialogField(parent.getDisplay()); + fWorkspaceRadio.attachDialogField(fWorkspaceFileNameField); + fExternalRadio.attachDialogFields(new DialogField[] { fExternalFileNameField, fExternalFolderButton, fEncodingCombo }); + } Dialog.applyDialogFont(composite); @@ -279,10 +348,20 @@ } private void attachmentChangeControlPressed(DialogField field) { - if (field == fFileNameField) { - IPath jarFilePath= isVariableEntry() ? chooseExtension() : chooseExtJarFile(); + if (field == fWorkspaceFileNameField) { + IPath jarFilePath= chooseInternal(); if (jarFilePath != null) { - fFileNameField.setText(jarFilePath.toString()); + fWorkspaceFileNameField.setText(jarFilePath.toString()); + } + } else if (field == fExternalFileNameField) { + IPath jarFilePath= chooseExtJarFile(); + if (jarFilePath != null) { + fExternalFileNameField.setText(jarFilePath.toString()); + } + } else if (field == fVariableFileNameField) { + IPath jarFilePath= chooseExtension(); + if (jarFilePath != null) { + fVariableFileNameField.setText(jarFilePath.toString()); } } } @@ -290,18 +369,16 @@ // ---------- IDialogFieldListener -------- private void attachmentDialogFieldChanged(DialogField field) { - if (field == fFileNameField) { - fNameStatus= updateFileNameStatus(); - } else if (field == fWorkspaceButton) { - IPath jarFilePath= chooseInternal(); - if (jarFilePath != null) { - fFileNameField.setText(jarFilePath.toString()); - } - return; + if (field == fVariableFileNameField) { + fVariableNameStatus= updateFileNameStatus(fVariableFileNameField); + } else if (field == fWorkspaceFileNameField) { + fWorkspaceNameStatus= updateFileNameStatus(fWorkspaceFileNameField); + } else if (field == fExternalFileNameField) { + fExternalNameStatus= updateFileNameStatus(fExternalFileNameField); } else if (field == fExternalFolderButton) { IPath folderPath= chooseExtFolder(); if (folderPath != null) { - fFileNameField.setText(folderPath.toString()); + fExternalFileNameField.setText(folderPath.toString()); } return; } @@ -309,14 +386,24 @@ } private void doStatusLineUpdate() { - fFileNameField.enableButton(canBrowseFileName()); - - // set the resolved path for variable jars - if (fFullPathResolvedLabel != null) { - fFullPathResolvedLabel.setText(getResolvedLabelString()); + IStatus status; + if (isVariableEntry()) { + // set the resolved path for variable jars + if (fFullPathResolvedLabel != null) { + fFullPathResolvedLabel.setText(getResolvedLabelString()); + } + fVariableFileNameField.enableButton(canBrowseFileName()); + status= fVariableNameStatus; + } else { + boolean isWorkSpace= fWorkspaceRadio.isSelected(); + if (isWorkSpace) { + fWorkspaceFileNameField.enableButton(canBrowseFileName()); + status= fWorkspaceNameStatus; + } else { + fExternalFileNameField.enableButton(canBrowseFileName()); + status= fExternalNameStatus; + } } - - IStatus status= StatusUtil.getMostSevere(new IStatus[] { fNameStatus }); fContext.statusChanged(status); } @@ -352,11 +439,11 @@ return null; } - private IStatus updateFileNameStatus() { + private IStatus updateFileNameStatus(StringButtonDialogField field) { StatusInfo status= new StatusInfo(); fFileVariablePath= null; - String fileName= fFileNameField.getText(); + String fileName= field.getText(); if (fileName.length() == 0) { // no source attachment return status; @@ -433,7 +520,8 @@ } private IPath getFilePath() { - return Path.fromOSString(fFileNameField.getText()).makeAbsolute(); + String filePath= isVariableEntry() ? fVariableFileNameField.getText() : (fWorkspaceRadio.isSelected() ? fWorkspaceFileNameField.getText() : fExternalFileNameField.getText()); + return Path.fromOSString(filePath).makeAbsolute(); } private IPath chooseExtension() { @@ -507,7 +595,7 @@ * Opens a dialog to choose an internal jar. */ private IPath chooseInternal() { - String initSelection= fFileNameField.getText(); + String initSelection= fWorkspaceFileNameField.getText(); ViewerFilter filter= new ArchiveFileFilter((List) null, false, false); @@ -585,7 +673,7 @@ return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { - String[] changedAttributes= { CPListElement.SOURCEATTACHMENT }; + String[] changedAttributes= { CPListElement.SOURCEATTACHMENT, CPListElement.SOURCE_ATTACHMENT_ENCODING }; BuildPathSupport.modifyClasspathEntry(shell, newEntry, changedAttributes, jproject, containerPath, isReferencedEntry, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); @@ -593,4 +681,24 @@ } }; } + + public static String getSourceAttachmentEncoding(IClasspathEntry entry) { + if (entry == null) { + throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$ + } + + int kind= entry.getEntryKind(); + if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) { + throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$ + } + + IClasspathAttribute[] extraAttributes= entry.getExtraAttributes(); + for (int i= 0; i < extraAttributes.length; i++) { + IClasspathAttribute attrib= extraAttributes[i]; + if (IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING.equals(attrib.getName())) { + return attrib.getValue(); + } + } + return null; + } } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/dialogfields/DialogField.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/dialogfields/DialogField.java index 3527987..66726f5 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/dialogfields/DialogField.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/wizards/dialogfields/DialogField.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -164,9 +164,9 @@ } /** - * Creates a spacer control with the given span. - * The composite is assumed to have MGridLayout as - * layout. + * Creates a spacer control with the given span. The composite is assumed to have + * GridLayout as layout. + * * @param parent The parent composite */ public static Control createEmptySpace(Composite parent, int span) {