|
From: <caw...@us...> - 2007-07-25 14:26:46
|
Revision: 2835
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=2835&view=rev
Author: cawilliams
Date: 2007-07-25 07:26:45 -0700 (Wed, 25 Jul 2007)
Log Message:
-----------
fix #5299 - Make gem loadpaths use variables that get resolved. Gem loadpaths now use the RUBY_LIB variable to make paths relative to the ruby library directory. This makes it so that oaths aren't absolute anymore and can be moved across workspaces/etc.
BUT, gems aren't always relative to the Ruby lib folder, so we really need to define a special GEM_LIB variable.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/NewRubyProjectPreferencePage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/AddSourceFolderWizardPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPListElement.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/LibrariesWorkbookPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/PreferenceConstants.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/BuildPathDialogAccess.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPVariableElement.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPVariableElementLabelProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/EditVariableEntryDialog.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/NewVariableEntryDialog.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/VariableBlock.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/VariableCreationDialog.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/VariablePathDialogField.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/NewRubyProjectPreferencePage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/NewRubyProjectPreferencePage.java 2007-07-24 17:31:10 UTC (rev 2834)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/preferences/NewRubyProjectPreferencePage.java 2007-07-25 14:26:45 UTC (rev 2835)
@@ -65,6 +65,7 @@
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo;
import org.rubypeople.rdt.internal.ui.dialogs.StatusUtil;
+import org.rubypeople.rdt.launching.RubyRuntime;
import org.rubypeople.rdt.ui.PreferenceConstants;
import org.rubypeople.rdt.ui.RubyUI;
@@ -273,11 +274,11 @@
}
private static ILoadpathEntry getJREContainerEntry() {
- return RubyCore.newContainerEntry(new Path("org.rubypeople.rdt.launching.RUBY_CONTAINER")); //$NON-NLS-1$
+ return RubyCore.newContainerEntry(new Path(RubyRuntime.RUBY_CONTAINER)); //$NON-NLS-1$
}
private static ILoadpathEntry getJREVariableEntry() {
- return RubyCore.newVariableEntry(new Path("RUBY_LIB")); //$NON-NLS-1$
+ return RubyCore.newVariableEntry(new Path(RubyRuntime.RUBYLIB_VARIABLE)); //$NON-NLS-1$
}
/*
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.java 2007-07-24 17:31:10 UTC (rev 2834)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.java 2007-07-25 14:26:45 UTC (rev 2835)
@@ -368,6 +368,57 @@
public static String SuperModuleSelectionDialog_addButton_label;
public static String SuperModuleSelectionDialog_interfaceadded_info;
public static String SuperModuleSelectionDialog_interfacealreadyadded_info;
+ public static String NewVariableEntryDialog_title;
+ public static String NewVariableEntryDialog_vars_extend;
+ public static String NewVariableEntryDialog_vars_label;
+ public static String NewVariableEntryDialog_configbutton_label;
+ public static String NewVariableEntryDialog_info_notexists;
+ public static String NewVariableEntryDialog_info_isfolder;
+ public static String NewVariableEntryDialog_info_noselection;
+ public static String NewVariableEntryDialog_info_selected;
+ public static String NewVariableEntryDialog_ExtensionDialog_title;
+ public static String NewVariableEntryDialog_ExtensionDialog_description;
+ public static String CPVariableElementLabelProvider_reserved;
+ public static String CPVariableElementLabelProvider_empty;
+ public static String EditVariableEntryDialog_title;
+ public static String EditVariableEntryDialog_filename_varlabel;
+ public static String EditVariableEntryDialog_filename_external_varbutton;
+ public static String EditVariableEntryDialog_filename_variable_button;
+ public static String EditVariableEntryDialog_extvardialog_title;
+ public static String EditVariableEntryDialog_extvardialog_description;
+ public static String EditVariableEntryDialog_filename_empty;
+ public static String EditVariableEntryDialog_filename_error_notvalid;
+ public static String EditVariableEntryDialog_filename_error_deviceinpath;
+ public static String EditVariableEntryDialog_filename_error_varnotexists;
+ public static String EditVariableEntryDialog_filename_warning_varempty;
+ public static String EditVariableEntryDialog_filename_error_filenotexists;
+ public static String EditVariableEntryDialog_filename_error_alreadyexists;
+ public static String VariablePathDialogField_variabledialog_title;
+ public static String VariableBlock_vars_add_button;
+ public static String VariableBlock_vars_edit_button;
+ public static String VariableBlock_vars_remove_button;
+ public static String VariableBlock_vars_label;
+ public static String VariableBlock_needsbuild_title;
+ public static String VariableBlock_needsbuild_message;
+ public static String VariableBlock_variableSettingError_titel;
+ public static String VariableBlock_variableSettingError_message;
+ public static String VariableBlock_operation_desc;
+ public static String VariableCreationDialog_titlenew;
+ public static String VariableCreationDialog_titleedit;
+ public static String VariableCreationDialog_name_label;
+ public static String VariableCreationDialog_path_label;
+ public static String VariableCreationDialog_path_file_button;
+ public static String VariableCreationDialog_path_dir_button;
+ public static String VariableCreationDialog_error_entername;
+ public static String VariableCreationDialog_error_whitespace;
+ public static String VariableCreationDialog_error_invalidname;
+ public static String VariableCreationDialog_error_nameexists;
+ public static String VariableCreationDialog_error_invalidpath;
+ public static String VariableCreationDialog_warning_pathnotexists;
+ public static String VariableCreationDialog_extjardialog_text;
+ public static String VariableCreationDialog_extdirdialog_text;
+ public static String VariableCreationDialog_extdirdialog_message;
+ public static String LibrariesWorkbookPage_libraries_addvariable_button;
static {
NLS.initializeMessages(BUNDLE_NAME, NewWizardMessages.class);
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/AddSourceFolderWizardPage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/AddSourceFolderWizardPage.java 2007-07-24 17:31:10 UTC (rev 2834)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/AddSourceFolderWizardPage.java 2007-07-25 14:26:45 UTC (rev 2835)
@@ -198,7 +198,6 @@
private final IPath fOrginalPath;
private final boolean fLinkedMode;
- private IPath fNewOutputLocation;
private CPListElement fOldProjectSourceFolder;
private List fModifiedElements;
@@ -476,11 +475,9 @@
if (!fAllowConflict && fCanCommitConflictingBuildpath)
return new StatusInfo();
- fNewOutputLocation= null;
IRubyModelStatus status= RubyConventions.validateLoadpath(javaProject, CPListElement.convertToLoadpathEntries(fExistingEntries), null);
if (!status.isOK()) {
//Don't know what the problem is, report to user
- fNewOutputLocation= null;
if (fCanCommitConflictingBuildpath) {
result.setInfo(NewWizardMessages.AddSourceFolderWizardPage_conflictWarning + status.getMessage());
} else {
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPListElement.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPListElement.java 2007-07-24 17:31:10 UTC (rev 2834)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPListElement.java 2007-07-25 14:26:45 UTC (rev 2835)
@@ -439,17 +439,15 @@
case ILoadpathEntry.CPE_VARIABLE:
IPath resolvedPath= RubyCore.getResolvedVariablePath(path);
res= null;
- isMissing= root.findMember(resolvedPath) == null && !resolvedPath.toFile().isFile();
+ isMissing= !resolvedPath.toFile().isDirectory();
break;
case ILoadpathEntry.CPE_LIBRARY:
res= root.findMember(path);
if (res == null) {
-// if (!ArchiveFileFilter.isArchivePath(path)) {
- if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()
- && root.getProject(path.segment(0)).exists()) {
- res= root.getFolder(path);
- }
-// }
+ if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()
+ && root.getProject(path.segment(0)).exists()) {
+ res= root.getFolder(path);
+ }
isMissing= !path.toFile().isDirectory(); // look for external Folders
} else if (res.isLinked()) {
linkTarget= res.getLocation();
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPVariableElement.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPVariableElement.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPVariableElement.java 2007-07-25 14:26:45 UTC (rev 2835)
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.wizards.buildpaths;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.util.Assert;
+
+
+public class CPVariableElement {
+
+ private String fName;
+ private IPath fPath;
+
+ private boolean fIsReserved;
+
+ public CPVariableElement(String name, IPath path, boolean reserved) {
+ Assert.isNotNull(name);
+ Assert.isNotNull(path);
+ fName= name;
+ fPath= path;
+ fIsReserved= reserved;
+ }
+
+ /**
+ * Gets the path
+ * @return Returns a IPath
+ */
+ public IPath getPath() {
+ return fPath;
+ }
+
+ /**
+ * Sets the path
+ * @param path The path to set
+ */
+ public void setPath(IPath path) {
+ fPath= path;
+ }
+
+ /**
+ * Gets the name
+ * @return Returns a String
+ */
+ public String getName() {
+ return fName;
+ }
+
+ /**
+ * Sets the name
+ * @param name The name to set
+ */
+ public void setName(String name) {
+ fName= name;
+ }
+
+ /*
+ * @see Object#equals()
+ */
+ public boolean equals(Object other) {
+ if (other != null && other.getClass().equals(getClass())) {
+ CPVariableElement elem= (CPVariableElement)other;
+ return fName.equals(elem.fName);
+ }
+ return false;
+ }
+
+ /*
+ * @see Object#hashCode()
+ */
+ public int hashCode() {
+ return fName.hashCode();
+ }
+
+ /**
+ * Returns true if variable is reserved
+ * @return Returns a boolean
+ */
+ public boolean isReserved() {
+ return fIsReserved;
+ }
+
+ /**
+ * Sets the isReserved
+ * @param isReserved The state to set
+ */
+ public void setReserved(boolean isReserved) {
+ fIsReserved= isReserved;
+ }
+
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPVariableElement.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPVariableElementLabelProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPVariableElementLabelProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPVariableElementLabelProvider.java 2007-07-25 14:26:45 UTC (rev 2835)
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.wizards.buildpaths;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+
+
+public class CPVariableElementLabelProvider extends LabelProvider implements IColorProvider {
+
+ private Image fJARImage;
+ private Image fFolderImage;
+ private boolean fShowResolvedVariables;
+
+ private Color fResolvedBackground;
+
+ public CPVariableElementLabelProvider(boolean showResolvedVariables) {
+ ImageRegistry reg= RubyPlugin.getDefault().getImageRegistry();
+ fJARImage= reg.get(RubyPluginImages.IMG_OBJS_EXTJAR);
+ fFolderImage= PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
+ fShowResolvedVariables= showResolvedVariables;
+ fResolvedBackground= null;
+ }
+
+ /*
+ * @see LabelProvider#getImage(java.lang.Object)
+ */
+ public Image getImage(Object element) {
+ if (element instanceof CPVariableElement) {
+ CPVariableElement curr= (CPVariableElement) element;
+ IPath path= curr.getPath();
+ if (path.toFile().isFile()) {
+ return fJARImage;
+ }
+ return fFolderImage;
+ }
+ return super.getImage(element);
+ }
+
+ /*
+ * @see LabelProvider#getText(java.lang.Object)
+ */
+ public String getText(Object element) {
+ if (element instanceof CPVariableElement) {
+ CPVariableElement curr= (CPVariableElement)element;
+ String name= curr.getName();
+ IPath path= curr.getPath();
+ StringBuffer buf= new StringBuffer(name);
+ if (curr.isReserved()) {
+ buf.append(' ');
+ buf.append(NewWizardMessages.CPVariableElementLabelProvider_reserved);
+ }
+ if (path != null) {
+ buf.append(" - "); //$NON-NLS-1$
+ if (!path.isEmpty()) {
+ buf.append(path.toOSString());
+ } else {
+ buf.append(NewWizardMessages.CPVariableElementLabelProvider_empty);
+ }
+ }
+ return buf.toString();
+ }
+
+
+ return super.getText(element);
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
+ */
+ public Color getForeground(Object element) {
+ return null;
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
+ */
+ public Color getBackground(Object element) {
+ if (element instanceof CPVariableElement) {
+ CPVariableElement curr= (CPVariableElement) element;
+ if (!fShowResolvedVariables && curr.isReserved()) {
+ if (fResolvedBackground == null) {
+ Display display= Display.getCurrent();
+ fResolvedBackground= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
+ }
+ return fResolvedBackground;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
+ */
+ public void dispose() {
+ super.dispose();
+ }
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/CPVariableElementLabelProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/EditVariableEntryDialog.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/EditVariableEntryDialog.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/EditVariableEntryDialog.java 2007-07-25 14:26:45 UTC (rev 2835)
@@ -0,0 +1,299 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.wizards.buildpaths;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.StatusDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.corext.util.Messages;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.DialogField;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.LayoutUtil;
+
+/**
+ */
+public class EditVariableEntryDialog extends StatusDialog {
+
+ /**
+ * The path to which the archive variable points.
+ * Null if invalid path or not resolvable. Must not exist.
+ */
+ private IPath fFileVariablePath;
+
+ private IStatus fNameStatus;
+
+ private Set fExistingEntries;
+ private VariablePathDialogField fFileNameField;
+ private CLabel fFullPathResolvedLabel;
+
+ /**
+ * Constructor for EditVariableEntryDialog.
+ * @param parent
+ */
+ public EditVariableEntryDialog(Shell parent, IPath initialEntry, IPath[] existingEntries) {
+ super(parent);
+ setTitle(NewWizardMessages.EditVariableEntryDialog_title);
+
+ fExistingEntries= new HashSet();
+ if (existingEntries != null) {
+ for (int i = 0; i < existingEntries.length; i++) {
+ IPath curr= existingEntries[i];
+ if (!curr.equals(initialEntry)) {
+ fExistingEntries.add(curr);
+ }
+ }
+ }
+
+ SourceAttachmentAdapter adapter= new SourceAttachmentAdapter();
+
+ fFileNameField= new VariablePathDialogField(adapter);
+ fFileNameField.setDialogFieldListener(adapter);
+ fFileNameField.setLabelText(NewWizardMessages.EditVariableEntryDialog_filename_varlabel);
+ fFileNameField.setButtonLabel(NewWizardMessages.EditVariableEntryDialog_filename_external_varbutton);
+ fFileNameField.setVariableButtonLabel(NewWizardMessages.EditVariableEntryDialog_filename_variable_button);
+ String initialString= initialEntry != null ? initialEntry.toString() : ""; //$NON-NLS-1$
+ fFileNameField.setText(initialString);
+ }
+
+ public IPath getPath() {
+ return Path.fromOSString(fFileNameField.getText());
+ }
+
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea(Composite parent) {
+ initializeDialogUnits(parent);
+ Composite composite= (Composite) super.createDialogArea(parent);
+
+ GridLayout layout= (GridLayout) composite.getLayout();
+ layout.numColumns= 3;
+
+ int widthHint= convertWidthInCharsToPixels(50);
+
+ GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ gd.horizontalSpan= 3;
+
+ // archive name field
+ fFileNameField.doFillIntoGrid(composite, 4);
+ LayoutUtil.setHorizontalSpan(fFileNameField.getLabelControl(null), 3);
+ LayoutUtil.setWidthHint(fFileNameField.getTextControl(null), widthHint);
+ LayoutUtil.setHorizontalGrabbing(fFileNameField.getTextControl(null));
+
+ // label that shows the resolved path for variable jars
+ //DialogField.createEmptySpace(composite, 1);
+ fFullPathResolvedLabel= new CLabel(composite, SWT.LEFT);
+ fFullPathResolvedLabel.setText(getResolvedLabelString());
+ fFullPathResolvedLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+ DialogField.createEmptySpace(composite, 2);
+
+
+ fFileNameField.postSetFocusOnDialogField(parent.getDisplay());
+
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IRubyHelpContextIds.SOURCE_ATTACHMENT_BLOCK);
+ applyDialogFont(composite);
+ return composite;
+ }
+
+ private class SourceAttachmentAdapter implements IStringButtonAdapter, IDialogFieldListener {
+
+ // -------- IStringButtonAdapter --------
+ public void changeControlPressed(DialogField field) {
+ attachmentChangeControlPressed(field);
+ }
+
+ // ---------- IDialogFieldListener --------
+ public void dialogFieldChanged(DialogField field) {
+ attachmentDialogFieldChanged(field);
+ }
+ }
+
+ private void attachmentChangeControlPressed(DialogField field) {
+// if (field == fFileNameField) {
+// IPath jarFilePath= chooseExtJarFile();
+// if (jarFilePath != null) {
+// fFileNameField.setText(jarFilePath.toString());
+// }
+// }
+ }
+
+ // ---------- IDialogFieldListener --------
+
+ private void attachmentDialogFieldChanged(DialogField field) {
+ if (field == fFileNameField) {
+ fNameStatus= updateFileNameStatus();
+ }
+ doStatusLineUpdate();
+ }
+
+
+// private IPath chooseExtJarFile() {
+// IPath currPath= getPath();
+// IPath resolvedPath= getResolvedPath(currPath);
+// File initialSelection= resolvedPath != null ? resolvedPath.toFile() : null;
+//
+// String currVariable= currPath.segment(0);
+// JARFileSelectionDialog dialog= new JARFileSelectionDialog(getShell(), false, false);
+// dialog.setTitle(NewWizardMessages.EditVariableEntryDialog_extvardialog_title);
+// dialog.setMessage(NewWizardMessages.EditVariableEntryDialog_extvardialog_description);
+// dialog.setInput(fFileVariablePath.toFile());
+// dialog.setInitialSelection(initialSelection);
+// if (dialog.open() == Window.OK) {
+// File result= (File) dialog.getResult()[0];
+// IPath returnPath= Path.fromOSString(result.getPath()).makeAbsolute();
+// return modifyPath(returnPath, currVariable);
+// }
+// return null;
+// }
+
+ private IPath getResolvedPath(IPath path) {
+ if (path != null) {
+ String varName= path.segment(0);
+ if (varName != null) {
+ IPath varPath= RubyCore.getLoadpathVariable(varName);
+ if (varPath != null) {
+ return varPath.append(path.removeFirstSegments(1));
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Takes a path and replaces the beginning with a variable name
+ * (if the beginning matches with the variables value)
+ */
+ private IPath modifyPath(IPath path, String varName) {
+ if (varName == null || path == null) {
+ return null;
+ }
+ if (path.isEmpty()) {
+ return new Path(varName);
+ }
+
+ IPath varPath= RubyCore.getLoadpathVariable(varName);
+ if (varPath != null) {
+ if (varPath.isPrefixOf(path)) {
+ path= path.removeFirstSegments(varPath.segmentCount());
+ } else {
+ path= new Path(path.lastSegment());
+ }
+ } else {
+ path= new Path(path.lastSegment());
+ }
+ return new Path(varName).append(path);
+ }
+
+ private IStatus updateFileNameStatus() {
+ StatusInfo status= new StatusInfo();
+ fFileVariablePath= null;
+
+ String fileName= fFileNameField.getText();
+ if (fileName.length() == 0) {
+ status.setError(NewWizardMessages.EditVariableEntryDialog_filename_empty);
+ return status;
+ } else {
+ if (!Path.EMPTY.isValidPath(fileName)) {
+ status.setError(NewWizardMessages.EditVariableEntryDialog_filename_error_notvalid);
+ return status;
+ }
+ IPath filePath= Path.fromOSString(fileName);
+ IPath resolvedPath;
+
+
+ if (filePath.getDevice() != null) {
+ status.setError(NewWizardMessages.EditVariableEntryDialog_filename_error_deviceinpath);
+ return status;
+ }
+ String varName= filePath.segment(0);
+ if (varName == null) {
+ status.setError(NewWizardMessages.EditVariableEntryDialog_filename_error_notvalid);
+ return status;
+ }
+ fFileVariablePath= RubyCore.getLoadpathVariable(varName);
+ if (fFileVariablePath == null) {
+ status.setError(NewWizardMessages.EditVariableEntryDialog_filename_error_varnotexists);
+ return status;
+ }
+ resolvedPath= fFileVariablePath.append(filePath.removeFirstSegments(1));
+
+ if (resolvedPath.isEmpty()) {
+ status.setWarning(NewWizardMessages.EditVariableEntryDialog_filename_warning_varempty);
+ return status;
+ }
+ File file= resolvedPath.toFile();
+ if (!file.isFile()) {
+ String message= Messages.format(NewWizardMessages.EditVariableEntryDialog_filename_error_filenotexists, resolvedPath.toOSString());
+ status.setInfo(message);
+ return status;
+ }
+ }
+ return status;
+ }
+
+ private String getResolvedLabelString() {
+ IPath resolvedPath= getResolvedPath(getPath());
+ if (resolvedPath != null) {
+ return resolvedPath.toOSString();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ private boolean canBrowseFileName() {
+ // to browse with a variable JAR, the variable name must point to a directory
+ if (fFileVariablePath != null) {
+ return fFileVariablePath.toFile().isDirectory();
+ }
+ return false;
+ }
+
+ private void doStatusLineUpdate() {
+ fFileNameField.enableButton(canBrowseFileName());
+
+ // set the resolved path for variable jars
+ if (fFullPathResolvedLabel != null) {
+ fFullPathResolvedLabel.setText(getResolvedLabelString());
+ }
+
+ IStatus status= fNameStatus;
+ if (!status.matches(IStatus.ERROR)) {
+ IPath path= getPath();
+ if (fExistingEntries.contains(path)) {
+ String message= NewWizardMessages.EditVariableEntryDialog_filename_error_alreadyexists;
+ status= new StatusInfo(IStatus.ERROR, message);
+ }
+ }
+ updateStatus(status);
+ }
+
+
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/EditVariableEntryDialog.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/LibrariesWorkbookPage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/LibrariesWorkbookPage.java 2007-07-24 17:31:10 UTC (rev 2834)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/LibrariesWorkbookPage.java 2007-07-25 14:26:45 UTC (rev 2835)
@@ -49,6 +49,7 @@
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
import org.rubypeople.rdt.core.ILoadpathEntry;
import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.internal.corext.util.Messages;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.actions.WorkbenchRunnableAdapter;
@@ -74,8 +75,9 @@
private Control fSWTControl;
private final int IDX_ADDEXT= 0;
- private final int IDX_EDIT= 2;
- private final int IDX_REMOVE= 3;
+ private final int IDX_ADDVAR= 1;
+ private final int IDX_EDIT= 3;
+ private final int IDX_REMOVE= 4;
public LibrariesWorkbookPage(CheckedListDialogField classPathList, IWorkbenchPreferenceContainer pageContainer) {
fClassPathList= classPathList;
@@ -83,6 +85,7 @@
String[] buttonLabels= new String[] {
NewWizardMessages.LibrariesWorkbookPage_libraries_addextjar_button,
+ NewWizardMessages.LibrariesWorkbookPage_libraries_addvariable_button,
/* */ null,
NewWizardMessages.LibrariesWorkbookPage_libraries_edit_button,
NewWizardMessages.LibrariesWorkbookPage_libraries_remove_button,
@@ -201,6 +204,9 @@
case IDX_ADDEXT: /* add external folder */
libentries= openExtFolderDialog(null);
break;
+ case IDX_ADDVAR: /* add variable */
+ libentries= openVariableSelectionDialog(null);
+ break;
case IDX_EDIT: /* edit */
editEntry();
return;
@@ -384,6 +390,9 @@
}
}
break;
+ case ILoadpathEntry.CPE_VARIABLE:
+ res= openVariableSelectionDialog(elem);
+ break;
}
if (res != null && res.length > 0) {
CPListElement curr= res[0];
@@ -538,4 +547,39 @@
}
}
}
+
+ private CPListElement[] openVariableSelectionDialog(CPListElement existing) {
+ List existingElements= fLibrariesList.getElements();
+ ArrayList existingPaths= new ArrayList(existingElements.size());
+ for (int i= 0; i < existingElements.size(); i++) {
+ CPListElement elem= (CPListElement) existingElements.get(i);
+ if (elem.getEntryKind() == ILoadpathEntry.CPE_VARIABLE) {
+ existingPaths.add(elem.getPath());
+ }
+ }
+ IPath[] existingPathsArray= (IPath[]) existingPaths.toArray(new IPath[existingPaths.size()]);
+
+ if (existing == null) {
+ IPath[] paths= BuildPathDialogAccess.chooseVariableEntries(getShell(), existingPathsArray);
+ if (paths != null) {
+ ArrayList result= new ArrayList();
+ for (int i = 0; i < paths.length; i++) {
+ CPListElement elem= new CPListElement(fCurrJProject, ILoadpathEntry.CPE_VARIABLE, paths[i], null);
+ IPath resolvedPath= RubyCore.getResolvedVariablePath(paths[i]);
+ elem.setIsMissing((resolvedPath == null) || !resolvedPath.toFile().exists());
+ if (!existingElements.contains(elem)) {
+ result.add(elem);
+ }
+ }
+ return (CPListElement[]) result.toArray(new CPListElement[result.size()]);
+ }
+ } else {
+ IPath path= BuildPathDialogAccess.configureVariableEntry(getShell(), existing.getPath(), existingPathsArray);
+ if (path != null) {
+ CPListElement elem= new CPListElement(fCurrJProject, ILoadpathEntry.CPE_VARIABLE, path, null);
+ return new CPListElement[] { elem };
+ }
+ }
+ return null;
+ }
}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/NewVariableEntryDialog.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/NewVariableEntryDialog.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/NewVariableEntryDialog.java 2007-07-25 14:26:45 UTC (rev 2835)
@@ -0,0 +1,292 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.wizards.buildpaths;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.StatusDialog;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.corext.util.Messages;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.DialogField;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.IListAdapter;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.LayoutUtil;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.ListDialogField;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
+
+public class NewVariableEntryDialog extends StatusDialog {
+
+ private class VariablesAdapter implements IDialogFieldListener, IListAdapter {
+
+ // -------- IListAdapter --------
+
+ public void customButtonPressed(ListDialogField field, int index) {
+ switch (index) {
+ case IDX_EXTEND: /* extend */
+ extendButtonPressed();
+ break;
+ }
+ }
+
+ public void selectionChanged(ListDialogField field) {
+ doSelectionChanged();
+ }
+
+ public void doubleClicked(ListDialogField field) {
+ doDoubleClick();
+ }
+
+ // ---------- IDialogFieldListener --------
+
+ public void dialogFieldChanged(DialogField field) {
+ if (field == fConfigButton) {
+ configButtonPressed();
+ }
+
+ }
+
+ }
+
+ private final int IDX_EXTEND= 0;
+
+ private ListDialogField fVariablesList;
+ private boolean fCanExtend;
+ private boolean fIsValidSelection;
+
+ private IPath[] fResultPaths;
+
+ private SelectionButtonDialogField fConfigButton;
+
+ public NewVariableEntryDialog(Shell parent) {
+ super(parent);
+ setTitle(NewWizardMessages.NewVariableEntryDialog_title);
+
+ int shellStyle= getShellStyle();
+ setShellStyle(shellStyle | SWT.MAX | SWT.RESIZE);
+ updateStatus(new StatusInfo(IStatus.ERROR, "")); //$NON-NLS-1$
+
+ String[] buttonLabels= new String[] {
+ NewWizardMessages.NewVariableEntryDialog_vars_extend,
+ };
+
+ VariablesAdapter adapter= new VariablesAdapter();
+
+ CPVariableElementLabelProvider labelProvider= new CPVariableElementLabelProvider(false);
+
+ fVariablesList= new ListDialogField(adapter, buttonLabels, labelProvider);
+ fVariablesList.setDialogFieldListener(adapter);
+ fVariablesList.setLabelText(NewWizardMessages.NewVariableEntryDialog_vars_label);
+
+ fVariablesList.enableButton(IDX_EXTEND, false);
+
+ fVariablesList.setViewerSorter(new ViewerSorter() {
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ if (e1 instanceof CPVariableElement && e2 instanceof CPVariableElement) {
+ return ((CPVariableElement)e1).getName().compareTo(((CPVariableElement)e2).getName());
+ }
+ return super.compare(viewer, e1, e2);
+ }
+ });
+
+
+ fConfigButton= new SelectionButtonDialogField(SWT.PUSH);
+ fConfigButton.setLabelText(NewWizardMessages.NewVariableEntryDialog_configbutton_label);
+ fConfigButton.setDialogFieldListener(adapter);
+
+ initializeElements();
+
+ fCanExtend= false;
+ fIsValidSelection= false;
+ fResultPaths= null;
+ }
+
+ private void initializeElements() {
+ String[] entries= RubyCore.getLoadpathVariableNames();
+ ArrayList elements= new ArrayList(entries.length);
+ for (int i= 0; i < entries.length; i++) {
+ String name= entries[i];
+ IPath entryPath= RubyCore.getLoadpathVariable(name);
+ if (entryPath != null) {
+ elements.add(new CPVariableElement(name, entryPath, false));
+ }
+ }
+
+ fVariablesList.setElements(elements);
+ }
+
+
+ /* (non-Rubydoc)
+ * @see Window#configureShell(Shell)
+ */
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IRubyHelpContextIds.NEW_VARIABLE_ENTRY_DIALOG);
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
+ */
+ protected IDialogSettings getDialogBoundsSettings() {
+ return RubyPlugin.getDefault().getDialogSettingsSection(getClass().getName());
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite composite= (Composite) super.createDialogArea(parent);
+ GridLayout layout= (GridLayout) composite.getLayout();
+ layout.numColumns= 2;
+
+ fVariablesList.doFillIntoGrid(composite, 3);
+
+ LayoutUtil.setHorizontalSpan(fVariablesList.getLabelControl(null), 2);
+
+ GridData listData= (GridData) fVariablesList.getListControl(null).getLayoutData();
+ listData.grabExcessHorizontalSpace= true;
+ listData.heightHint= convertHeightInCharsToPixels(10);
+ listData.widthHint= convertWidthInCharsToPixels(70);
+
+ Composite lowerComposite= new Composite(composite, SWT.NONE);
+ lowerComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+
+ layout= new GridLayout();
+ layout.marginHeight= 0;
+ layout.marginWidth= 0;
+ lowerComposite.setLayout(layout);
+
+ fConfigButton.doFillIntoGrid(lowerComposite, 1);
+
+ applyDialogFont(composite);
+ return composite;
+ }
+
+ public IPath[] getResult() {
+ return fResultPaths;
+ }
+
+ /*
+ * @see IDoubleClickListener#doubleClick(DoubleClickEvent)
+ */
+ private void doDoubleClick() {
+ if (fIsValidSelection) {
+ okPressed();
+ } else if (fCanExtend) {
+ extendButtonPressed();
+ }
+ }
+
+ private void doSelectionChanged() {
+ boolean isValidSelection= true;
+ boolean canExtend= false;
+ StatusInfo status= new StatusInfo();
+
+ List selected= fVariablesList.getSelectedElements();
+ int nSelected= selected.size();
+
+ if (nSelected > 0) {
+ fResultPaths= new Path[nSelected];
+ for (int i= 0; i < nSelected; i++) {
+ CPVariableElement curr= (CPVariableElement) selected.get(i);
+ fResultPaths[i]= new Path(curr.getName());
+ File file= curr.getPath().toFile();
+ if (!file.exists()) {
+ status.setError(NewWizardMessages.NewVariableEntryDialog_info_notexists);
+ isValidSelection= false;
+ break;
+ }
+ if (file.isDirectory()) {
+ status.setError(NewWizardMessages.NewVariableEntryDialog_info_isfolder);
+ canExtend= true;
+ isValidSelection= false;
+ break;
+ }
+ }
+ } else {
+ isValidSelection= false;
+ status.setInfo(NewWizardMessages.NewVariableEntryDialog_info_noselection);
+ }
+ if (isValidSelection && nSelected > 1) {
+ String str= Messages.format(NewWizardMessages.NewVariableEntryDialog_info_selected, String.valueOf(nSelected));
+ status.setInfo(str);
+ }
+ fCanExtend= nSelected == 1 && canExtend;
+ fVariablesList.enableButton(0, fCanExtend);
+
+ updateStatus(status);
+ fIsValidSelection= isValidSelection;
+ Button okButton= getButton(IDialogConstants.OK_ID);
+ if (okButton != null && !okButton.isDisposed()) {
+ okButton.setEnabled(isValidSelection);
+ }
+ }
+
+ private IPath[] chooseExtensions(CPVariableElement elem) {
+ File file= elem.getPath().toFile();
+ DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN);
+ dialog.setText(NewWizardMessages.NewVariableEntryDialog_ExtensionDialog_title);
+ dialog.setMessage(Messages.format(NewWizardMessages.NewVariableEntryDialog_ExtensionDialog_description, elem.getName()));
+ dialog.setFilterPath(file.toString());
+ String filename = null;
+ if ((filename = dialog.open()) != null) {
+ File myFile = new File(filename);
+ IPath filePath= Path.fromOSString(myFile.getPath());
+ IPath resPath= new Path(elem.getName());
+ for (int k= elem.getPath().segmentCount(); k < filePath.segmentCount(); k++) {
+ resPath= resPath.append(filePath.segment(k));
+ }
+ return new IPath[] { resPath };
+ }
+ return null;
+ }
+
+ protected final void extendButtonPressed() {
+ List selected= fVariablesList.getSelectedElements();
+ if (selected.size() == 1) {
+ IPath[] extendedPaths= chooseExtensions((CPVariableElement) selected.get(0));
+ if (extendedPaths != null) {
+ fResultPaths= extendedPaths;
+ super.buttonPressed(IDialogConstants.OK_ID);
+ }
+ }
+ }
+
+ protected final void configButtonPressed() {
+// String id= LoadpathVariablesPreferencePage.ID; FIXME Uncomment this
+// PreferencesUtil.createPreferenceDialogOn(getShell(), id, new String[] { id }, null).open();
+ initializeElements();
+ }
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/NewVariableEntryDialog.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/VariableBlock.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/VariableBlock.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/VariableBlock.java 2007-07-25 14:26:45 UTC (rev 2835)
@@ -0,0 +1,428 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.wizards.buildpaths;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.rubypeople.rdt.core.ILoadpathEntry;
+import org.rubypeople.rdt.core.IRubyModel;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.util.CoreUtility;
+import org.rubypeople.rdt.internal.ui.util.ExceptionHandler;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.DialogField;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.IListAdapter;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.LayoutUtil;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.ListDialogField;
+import org.rubypeople.rdt.launching.RubyRuntime;
+
+
+public class VariableBlock {
+
+ private ListDialogField fVariablesList;
+ private Control fControl;
+ private boolean fHasChanges;
+
+ private List fSelectedElements;
+ private boolean fAskToBuild;
+ private boolean fInPreferencePage;
+
+
+ /**
+ * Constructor for VariableBlock
+ */
+ public VariableBlock(boolean inPreferencePage, String initSelection) {
+
+ fSelectedElements= new ArrayList(0);
+ fInPreferencePage= inPreferencePage;
+ fAskToBuild= true;
+
+ String[] buttonLabels= new String[] {
+ NewWizardMessages.VariableBlock_vars_add_button,
+ NewWizardMessages.VariableBlock_vars_edit_button,
+ NewWizardMessages.VariableBlock_vars_remove_button
+ };
+
+ VariablesAdapter adapter= new VariablesAdapter();
+
+ CPVariableElementLabelProvider labelProvider= new CPVariableElementLabelProvider(!inPreferencePage);
+
+ fVariablesList= new ListDialogField(adapter, buttonLabels, labelProvider);
+ fVariablesList.setDialogFieldListener(adapter);
+ fVariablesList.setLabelText(NewWizardMessages.VariableBlock_vars_label);
+ fVariablesList.setRemoveButtonIndex(2);
+
+ fVariablesList.enableButton(1, false);
+
+ fVariablesList.setViewerSorter(new ViewerSorter() {
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ if (e1 instanceof CPVariableElement && e2 instanceof CPVariableElement) {
+ return ((CPVariableElement)e1).getName().compareTo(((CPVariableElement)e2).getName());
+ }
+ return super.compare(viewer, e1, e2);
+ }
+ });
+ refresh(initSelection);
+ }
+
+ public boolean hasChanges() {
+ return fHasChanges;
+ }
+
+ public void setChanges(boolean hasChanges) {
+ fHasChanges= hasChanges;
+ }
+
+
+ private String[] getReservedVariableNames() {
+ return new String[] {
+ RubyRuntime.RUBYLIB_VARIABLE
+ };
+ }
+
+ public Control createContents(Composite parent) {
+ Composite composite= new Composite(parent, SWT.NONE);
+ composite.setFont(parent.getFont());
+
+ LayoutUtil.doDefaultLayout(composite, new DialogField[] { fVariablesList }, true, 0, 0);
+ LayoutUtil.setHorizontalGrabbing(fVariablesList.getListControl(null));
+
+ fControl= composite;
+ return composite;
+ }
+
+ public void addDoubleClickListener(IDoubleClickListener listener) {
+ fVariablesList.getTableViewer().addDoubleClickListener(listener);
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ fVariablesList.getTableViewer().addSelectionChangedListener(listener);
+ }
+
+
+ private Shell getShell() {
+ if (fControl != null) {
+ return fControl.getShell();
+ }
+ return RubyPlugin.getActiveWorkbenchShell();
+ }
+
+ private class VariablesAdapter implements IDialogFieldListener, IListAdapter {
+
+ // -------- IListAdapter --------
+
+ public void customButtonPressed(ListDialogField field, int index) {
+ switch (index) {
+ case 0: /* add */
+ editEntries(null);
+ break;
+ case 1: /* edit */
+ List selected= field.getSelectedElements();
+ editEntries((CPVariableElement)selected.get(0));
+ break;
+ }
+ }
+
+ public void selectionChanged(ListDialogField field) {
+ doSelectionChanged(field);
+ }
+
+ public void doubleClicked(ListDialogField field) {
+ if (fInPreferencePage) {
+ List selected= field.getSelectedElements();
+ if (canEdit(selected, containsReserved(selected))) {
+ editEntries((CPVariableElement) selected.get(0));
+ }
+ }
+ }
+
+ // ---------- IDialogFieldListener --------
+
+ public void dialogFieldChanged(DialogField field) {
+ }
+
+ }
+
+ private boolean containsReserved(List selected) {
+ for (int i= selected.size()-1; i >= 0; i--) {
+ if (((CPVariableElement)selected.get(i)).isReserved()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static void addAll(Object[] objs, Collection dest) {
+ for (int i= 0; i < objs.length; i++) {
+ dest.add(objs[i]);
+ }
+ }
+
+ private boolean canEdit(List selected, boolean containsReserved) {
+ return selected.size() == 1 && !containsReserved;
+ }
+
+ private void doSelectionChanged(DialogField field) {
+ List selected= fVariablesList.getSelectedElements();
+ boolean containsReserved= containsReserved(selected);
+
+ // edit
+ fVariablesList.enableButton(1, canEdit(selected, containsReserved));
+ // remove button
+ fVariablesList.enableButton(2, !containsReserved);
+
+ fSelectedElements= selected;
+ }
+
+ private void editEntries(CPVariableElement entry) {
+ List existingEntries= fVariablesList.getElements();
+
+ VariableCreationDialog dialog= new VariableCreationDialog(getShell(), entry, existingEntries);
+ if (dialog.open() != Window.OK) {
+ return;
+ }
+ CPVariableElement newEntry= dialog.getClasspathElement();
+ if (entry == null) {
+ fVariablesList.addElement(newEntry);
+ entry= newEntry;
+ fHasChanges= true;
+ } else {
+ boolean hasChanges= !(entry.getName().equals(newEntry.getName()) && entry.getPath().equals(newEntry.getPath()));
+ if (hasChanges) {
+ fHasChanges= true;
+ entry.setName(newEntry.getName());
+ entry.setPath(newEntry.getPath());
+ fVariablesList.refresh();
+ }
+ }
+ fVariablesList.selectElements(new StructuredSelection(entry));
+ }
+
+ public List getSelectedElements() {
+ return fSelectedElements;
+ }
+
+
+ public void performDefaults() {
+ fVariablesList.removeAllElements();
+ String[] reservedName= getReservedVariableNames();
+ for (int i= 0; i < reservedName.length; i++) {
+ CPVariableElement elem= new CPVariableElement(reservedName[i], Path.EMPTY, true);
+ elem.setReserved(true);
+ fVariablesList.addElement(elem);
+ }
+ fHasChanges= true;
+ }
+
+ public boolean performOk() {
+ ArrayList removedVariables= new ArrayList();
+ ArrayList changedVariables= new ArrayList();
+ removedVariables.addAll(Arrays.asList(RubyCore.getLoadpathVariableNames()));
+
+ // remove all unchanged
+ List changedElements= fVariablesList.getElements();
+ for (int i= changedElements.size()-1; i >= 0; i--) {
+ CPVariableElement curr= (CPVariableElement) changedElements.get(i);
+ if (curr.isReserved()) {
+ changedElements.remove(curr);
+ } else {
+ IPath path= curr.getPath();
+ IPath prevPath= RubyCore.getLoadpathVariable(curr.getName());
+ if (prevPath != null && prevPath.equals(path)) {
+ changedElements.remove(curr);
+ } else {
+ changedVariables.add(curr.getName());
+ }
+ }
+ removedVariables.remove(curr.getName());
+ }
+ int steps= changedElements.size() + removedVariables.size();
+ if (steps > 0) {
+
+ boolean needsBuild= false;
+ if (fAskToBuild && doesChangeRequireFullBuild(removedVariables, changedVariables)) {
+ String title= NewWizardMessages.VariableBlock_needsbuild_title;
+ String message= NewWizardMessages.VariableBlock_needsbuild_message;
+
+ MessageDialog buildDialog= new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 2);
+ int res= buildDialog.open();
+ if (res != 0 && res != 1) {
+ return false;
+ }
+ needsBuild= (res == 0);
+ }
+
+ final VariableBlockRunnable runnable= new VariableBlockRunnable(removedVariables, changedElements);
+ final ProgressMonitorDialog dialog= new ProgressMonitorDialog(getShell());
+ try {
+ dialog.run(true, true, runnable);
+ } catch (InvocationTargetException e) {
+ ExceptionHandler.handle(new InvocationTargetException(new NullPointerException()), getShell(), NewWizardMessages.VariableBlock_variableSettingError_titel, NewWizardMessages.VariableBlock_variableSettingError_message);
+ return false;
+ } catch (InterruptedException e) {
+ return false;
+ }
+
+ if (needsBuild) {
+ CoreUtility.getBuildJob(null).schedule();
+ }
+ }
+ return true;
+ }
+
+ private boolean doesChangeRequireFullBuild(List removed, List changed) {
+ try {
+ IRubyModel model= RubyCore.create(ResourcesPlugin.getWorkspace().getRoot());
+ IRubyProject[] projects= model.getRubyProjects();
+ for (int i= 0; i < projects.length; i++) {
+ ILoadpathEntry[] entries= projects[i].getRawLoadpath();
+ for (int k= 0; k < entries.length; k++) {
+ ILoadpathEntry curr= entries[k];
+ if (curr.getEntryKind() == ILoadpathEntry.CPE_VARIABLE) {
+ String var= curr.getPath().segment(0);
+ if (removed.contains(var) || changed.contains(var)) {
+ return true;
+ }
+ }
+ }
+ }
+ } catch (RubyModelException e) {
+ return true;
+ }
+ return false;
+ }
+
+ private class VariableBlockRunnable implements IRunnableWithProgress {
+ private List fToRemove;
+ private List fToChange;
+
+ public VariableBlockRunnable(List toRemove, List toChange) {
+ fToRemove= toRemove;
+ fToChange= toChange;
+ }
+
+ /*
+ * @see IRunnableWithProgress#run(IProgressMonitor)
+ */
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ monitor.beginTask(NewWizardMessages.VariableBlock_operation_desc, 1);
+ try {
+ setVariables(monitor);
+
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ } catch (OperationCanceledException e) {
+ throw new InterruptedException();
+ } finally {
+ monitor.done();
+ }
+ }
+
+ public void setVariables(IProgressMonitor monitor) throws RubyModelException, CoreException {
+ int nVariables= fToChange.size() + fToRemove.size();
+
+ String[] names= new String[nVariables];
+ IPath[] paths= new IPath[nVariables];
+ int k= 0;
+
+ for (int i= 0; i < fToChange.size(); i++) {
+ CPVariableElement curr= (CPVariableElement) fToChange.get(i);
+ names[k]= curr.getName();
+ paths[k]= curr.getPath();
+ k++;
+ }
+ for (int i= 0; i < fToRemove.size(); i++) {
+ names[k]= (String) fToRemove.get(i);
+ paths[k]= null;
+ k++;
+ }
+ RubyCore.setLoadpathVariables(names, paths, new SubProgressMonitor(monitor, 1));
+ }
+ }
+
+ /**
+ * If set to true, a dialog will ask the user to build on variable changed
+ * @param askToBuild The askToBuild to set
+ */
+ public void setAskToBuild(boolean askToBuild) {
+ fAskToBuild= askToBuild;
+ }
+
+ /**
+ *
+ */
+ public void refresh(String initSelection) {
+ CPVariableElement initSelectedElement= null;
+
+ String[] reservedName= getReservedVariableNames();
+ ArrayList reserved= new ArrayList(reservedName.length);
+ addAll(reservedName, reserved);
+
+ String[] entries= RubyCore.getLoadpathVariableNames();
+ ArrayList elements= new ArrayList(entries.length);
+ for (int i= 0; i < entries.length; i++) {
+ String name= entries[i];
+ CPVariableElement elem;
+ IPath entryPath= RubyCore.getLoadpathVariable(name);
+ if (entryPath != null) {
+ elem= new CPVariableElement(name, entryPath, reserved.contains(name));
+ elements.add(elem);
+ if (name.equals(initSelection)) {
+ initSelectedElement= elem;
+ }
+ } else {
+ RubyPlugin.logErrorMessage("VariableBlock: Loadpath variable with null value: " + name); //$NON-NLS-1$
+ }
+ }
+
+ fVariablesList.setElements(elements);
+
+ if (initSelectedElement != null) {
+ ISelection sel= new StructuredSelection(initSelectedElement);
+ fVariablesList.selectElements(sel);
+ } else {
+ fVariablesList.selectFirstElement();
+ }
+
+ fHasChanges= false;
+ }
+
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/VariableBlock.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/VariableCreationDialog.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/VariableCreationDialog.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/buildpaths/VariableCreationDialog.java 2007-07-25 14:26:45 UTC (rev 2835)
@@ -0,0 +1,284 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.wizards.buildpaths;
+
+import java.io.File;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.dialogs.StatusDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.IUIConstants;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo;
+import org.rubypeople.rdt.internal.ui.dialogs.StatusUtil;
+import org.rubypeople.rdt.internal.ui.wizards.NewWizardMessages;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.DialogField;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.LayoutUtil;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
+import org.rubypeople.rdt.internal.ui.wizards.dialogfields.StringDialogField;
+
+public class VariableCreationDialog extends StatusDialog {
+
+ private IDialogSettings fDialogSettings;
+ ...
[truncated message content] |