Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Heads-up to managed build developers

Hi Sean,
 
Attached is the patch for the Build Manager Properties Page File List Buttons. 
 
Please let me know if you have any questions.
 
Regards,
 
Mike Charls
BitMethods, Inc.
----- Original Message -----
From: Sean Evoy
Sent: Friday, April 02, 2004 12:36 PM
Subject: Re: [cdt-dev] Heads-up to managed build developers


That looks very sharp. Submit it and I will commit it.

Sean Evoy
Rational Software - IBM Software Group
Ottawa, Ontario, Canada



"Mike Charls" <mcharls@xxxxxxxxxxxxxx>
Sent by: cdt-dev-admin@xxxxxxxxxxx

04/02/2004 02:20 PM

Please respond to
cdt-dev

To
<cdt-dev@xxxxxxxxxxx>
cc
Subject
Re: [cdt-dev] Heads-up to managed build developers





Hi Sean:
 
Adding the browseType attribute is fine with us.
 
one more thing (now that you are looking at this area)...  the Add, Remove, Move Up and Move Down buttons are always off the screen for the File items.  They are too far to the right, so the user always needs to scroll over see the buttons.  This is a minor point, but still a pain for the end-user.
 
We changed this in our application to place the buttons at the top of the file list (like a toolbar).  Attached is a screen snapshot.  This approach is similar to how Windows handles File lists.  
 
We use these file list buttons for the include Directories, Symbols, Libraries, and Other Options categories in the Build manager properties.  
 
If you would like to use this approach for the user interface, we can send you a patch.
 
Regards,
 
Mike Charls
BitMethods, Inc.
----- Original Message -----
From: Sean Evoy
To: cdt-dev@xxxxxxxxxxx
Sent: Thursday, April 01, 2004 8:25 AM
Subject: [cdt-dev] Heads-up to managed build developers


Hi Guys,

I just wanted to bounce a couple of ideas off the people who are looking at, and working on, the managed build system. First, there has been an endless stream of requests to put a browse button on path or file options. Since an IOption does not know what type of list it contains, I am proposing a new enumerated attribute in the option schema called "browseType". It will contain "none", "file", or "directory" so the UI can properly decide whether to display a browse button or not. So far, the solution does not break existing manifest definitions and the UI is working properly. I would like to know if anyone has a problem with this solution or if it tramples on something you have already done.


What this does not solve is the problem where the SWT/JFace widgets answer the file location or path location in the OS-appropriate format but the tools require these specifications in a different format. For example, imagine a cross-compiler hosted on Win32 not liking C:\foo\include, which is what we get back from the browse dialog. This might require some further tweaking of the toolchain model to get more information about the file system type the hosted tools prefer to use. Notice how studiously I am avoiding the term "target model" :-)


The window to propose alternatives is small, so if you have any strong opinions on this, please let me know asap.


Sean Evoy
Rational Software - IBM Software Group
Ottawa, Ontario, Canada

Index: src/org/eclipse/cdt/managedbuilder/internal/ui/ManagedBuilderUIImages.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/ManagedBuilderUIImages.java,v
retrieving revision 1.2
diff -u -r1.2 ManagedBuilderUIImages.java
--- src/org/eclipse/cdt/managedbuilder/internal/ui/ManagedBuilderUIImages.java	16 Mar 2004 22:26:10 -0000	1.2
+++ src/org/eclipse/cdt/managedbuilder/internal/ui/ManagedBuilderUIImages.java	6 Apr 2004 05:12:18 -0000
@@ -42,7 +42,8 @@
 	private static final String T= "full/"; //$NON-NLS-1$
 
 	public static final String T_BUILD= T + "build16/"; //$NON-NLS-1$
-
+	// list icons dir
+	public static final String T_LIST= T + "list/"; //$NON-NLS-1$
 
 
 	// For the managed build images
@@ -62,6 +63,19 @@
 	public static final ImageDescriptor DESC_BUILD_TOOL = createManaged(T_BUILD, IMG_BUILD_TOOL);
 	public static final String IMG_BUILD_CAT = NAME_PREFIX + "config-category.gif"; //$NON-NLS-1$
 	public static final ImageDescriptor DESC_BUILD_CAT = createManaged(T_BUILD, IMG_BUILD_CAT);
+	
+	// Image for file list control
+	public static final String IMG_FILELIST_ADD = NAME_PREFIX + "list-add.gif"; //$NON-NLS-1$
+	public static final ImageDescriptor DESC_FILELIST_ADD = createManaged(T_LIST, IMG_FILELIST_ADD);
+	public static final String IMG_FILELIST_DEL = NAME_PREFIX + "list-delete.gif"; //$NON-NLS-1$
+	public static final ImageDescriptor DESC_FILELIST_DEL = createManaged(T_LIST, IMG_FILELIST_DEL);
+	public static final String IMG_FILELIST_EDIT = NAME_PREFIX + "list-edit.gif"; //$NON-NLS-1$
+	public static final ImageDescriptor DESC_FILELIST_EDIT = createManaged(T_LIST, IMG_FILELIST_EDIT);
+	public static final String IMG_FILELIST_MOVEUP = NAME_PREFIX + "list-moveup.gif"; //$NON-NLS-1$
+	public static final ImageDescriptor DESC_FILELIST_MOVEUP = createManaged(T_LIST, IMG_FILELIST_MOVEUP);
+	public static final String IMG_FILELIST_MOVEDOWN = NAME_PREFIX + "list-movedown.gif"; //$NON-NLS-1$
+	public static final ImageDescriptor DESC_FILELIST_MOVEDOWN = createManaged(T_LIST, IMG_FILELIST_MOVEDOWN);
+	
 
 	
 	private static ImageDescriptor createManaged(String prefix, String name) {
Index: src/org/eclipse/cdt/managedbuilder/internal/ui/PluginResources.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/internal/ui/PluginResources.properties,v
retrieving revision 1.11
diff -u -r1.11 PluginResources.properties
--- src/org/eclipse/cdt/managedbuilder/internal/ui/PluginResources.properties	24 Mar 2004 21:11:54 -0000	1.11
+++ src/org/eclipse/cdt/managedbuilder/internal/ui/PluginResources.properties	6 Apr 2004 05:12:18 -0000
@@ -93,4 +93,21 @@
 # ----------- Default flag names -----------
 BuildToolSettingsPage.compilerflags=Other flags
 BuildToolSettingsPage.linkerflags=Linker flags
-BuildToolSettingsPage.alloptions=All Options
\ No newline at end of file
+BuildToolSettingsPage.alloptions=All Options
+
+# ----------- File List Control -----------
+FileListControl.add=Add
+FileListControl.delete=Delete
+FileListControl.edit=Edit
+FileListControl.moveup=Move Up
+FileListControl.movedown=Move Down
+FileListControl.filedialog.title=Select File
+FileListControl.dirdialog.title=Select Include Directory
+FileListControl.dirdialog.desc=Select Include Paths
+FileListControl.deletedialog.message=Are you sure you want to delete the selected directories?
+FileListControl.deletedialog.title=Confirm Delete
+FileListControl.editdialog.title=Edit Dialog
+FileListControl.newdialog.title=New Dialog
+
+
+
Index: src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java,v
retrieving revision 1.3
diff -u -r1.3 BuildOptionSettingsPage.java
--- src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java	24 Mar 2004 21:11:54 -0000	1.3
+++ src/org/eclipse/cdt/managedbuilder/ui/properties/BuildOptionSettingsPage.java	6 Apr 2004 05:12:18 -0000
@@ -83,13 +83,27 @@
 					addField(comboField);
 					fieldsList.add(comboField);
 					break;
-				case IOption.STRING_LIST :
 				case IOption.INCLUDE_PATH :
+					FileListControlFieldEditor incListField =
+						new FileListControlFieldEditor(
+							opt.getId(),
+							opt.getName(),
+							getFieldEditorParent(),
+							FileListControl.DIR_DIALOG);
+					addField(incListField);
+					fieldsList.add(incListField);
+					break;
+					
+				case IOption.STRING_LIST :
 				case IOption.PREPROCESSOR_SYMBOLS :
 				case IOption.LIBRARIES :
 				case IOption.OBJECTS :
-					BuildOptionListFieldEditor listField = new BuildOptionListFieldEditor(
-							opt.getId(), opt.getName(), getFieldEditorParent());
+					FileListControlFieldEditor listField =
+						new FileListControlFieldEditor(
+							opt.getId(),
+							opt.getName(),
+							getFieldEditorParent(),
+							FileListControl.TEXT_DIALOG);
 					addField(listField);
 					fieldsList.add(listField);
 					break;
Index: src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControl.java
===================================================================
RCS file: src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControl.java
diff -N src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControl.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControl.java	6 Apr 2004 05:12:19 -0000
@@ -0,0 +1,390 @@
+package org.eclipse.cdt.managedbuilder.ui.properties;
+
+/*******************************************************************************
+ * Copyright (c) 2004 BitMethods Inc and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Common Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/cpl-v10.html
+ * 
+ * Contributors: BitMethods Inc - Initial API and implementation
+ ******************************************************************************/
+
+import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIImages;
+import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swt.widgets.Widget;
+
+/**
+ * Instances of this class allow the user to add,remove, delete, moveup and movedown
+ * the items in the list control.
+ */
+
+public class FileListControl {
+	//toolbar
+	private ToolBar toolBar;
+	// toolbar items
+	private ToolItem titleItem, addItem, deleteItem, editItem, moveUpItem,
+			moveDownItem;
+	// title label
+	private Label title;
+	// images
+	private Image addImage, deleteImage, editImage, moveUpImage, moveDownImage;
+	private Composite composite;
+	// list control
+	private List list;
+	private String compTitle;
+	private SelectionListener selectionListener;
+	private GridData gdata, tgdata, grid3, grid4, grid2;
+	// types of dialogs that will be displayed when the add button is pressed.
+	public static final int FILE_DIALOG = 0;
+	public static final int DIR_DIALOG = 1;
+	public static final int TEXT_DIALOG = 2;
+	private int type;
+	private static final String ADD_STR = ManagedBuilderUIPlugin.getResourceString("FileListControl.add"); //$NON-NLS-1$
+	private static final String DEL_STR = ManagedBuilderUIPlugin.getResourceString("FileListControl.delete"); //$NON-NLS-1$
+	private static final String EDIT_STR = ManagedBuilderUIPlugin.getResourceString("FileListControl.edit"); //$NON-NLS-1$
+	private static final String MOVEUP_STR = ManagedBuilderUIPlugin.getResourceString("FileListControl.moveup"); //$NON-NLS-1$
+	private static final String MOVEDOWN_STR = ManagedBuilderUIPlugin.getResourceString("FileListControl.movedown"); //$NON-NLS-1$
+
+	//images
+	private final Image IMG_ADD = ManagedBuilderUIImages
+			.get(ManagedBuilderUIImages.IMG_FILELIST_ADD);
+	private final Image IMG_DEL = ManagedBuilderUIImages
+			.get(ManagedBuilderUIImages.IMG_FILELIST_DEL);
+	private final Image IMG_EDIT = ManagedBuilderUIImages
+			.get(ManagedBuilderUIImages.IMG_FILELIST_EDIT);
+	private final Image IMG_MOVEUP = ManagedBuilderUIImages
+			.get(ManagedBuilderUIImages.IMG_FILELIST_MOVEUP);
+	private final Image IMG_MOVEDOWN = ManagedBuilderUIImages
+			.get(ManagedBuilderUIImages.IMG_FILELIST_MOVEDOWN);
+	/**
+	 * Constructor
+	 * 
+	 * @param parent
+	 * @param compTitle
+	 * @param type
+	 */
+	public FileListControl(Composite parent, String compTitle, int type) {
+		this.type = type;
+		//file panel
+		Composite filePanel = new Composite(parent, SWT.NONE);
+		GridLayout form1 = new GridLayout();
+		form1.numColumns = 1;
+		form1.horizontalSpacing = 0;
+		form1.verticalSpacing = 0;
+		form1.marginHeight = 0;
+		form1.marginWidth = 0;
+		filePanel.setLayout(form1);
+		gdata = new GridData(GridData.FILL_BOTH);
+		gdata.heightHint = 83;
+		filePanel.setLayoutData(gdata);
+		// title panel
+		Composite titlePanel = new Composite(filePanel, SWT.BORDER);
+		GridLayout titleform = new GridLayout();
+		titleform.numColumns = 2;
+		titleform.horizontalSpacing = 0;
+		titleform.verticalSpacing = 0;
+		titleform.marginHeight = 0;
+		titleform.marginWidth = 0;
+		titlePanel.setLayout(titleform);
+		tgdata = new GridData(GridData.FILL_HORIZONTAL);
+		tgdata.heightHint = 22;
+		titlePanel.setLayoutData(tgdata);
+		title = new Label(titlePanel, SWT.NONE | SWT.BOLD);
+		this.compTitle = "  " + compTitle; //$NON-NLS-1$
+		title.setText(this.compTitle);
+		grid2 = new GridData(GridData.FILL_HORIZONTAL);
+		title.setLayoutData(grid2);
+		//button panel
+		Composite buttonPanel = new Composite(titlePanel, SWT.NONE);
+		GridLayout form2 = new GridLayout();
+		form2.numColumns = 5;
+		form2.horizontalSpacing = 0;
+		form2.verticalSpacing = 0;
+		form2.marginWidth = 0;
+		form2.marginHeight = 0;
+		buttonPanel.setLayout(form2);
+		// toolbar
+		toolBar = new ToolBar(buttonPanel, SWT.HORIZONTAL | SWT.RIGHT
+				| SWT.FLAT);
+		// add toolbar item
+		addItem = new ToolItem(toolBar, SWT.PUSH);
+		addItem.setImage(IMG_ADD);
+		addItem.setToolTipText(ADD_STR);
+		addItem.addSelectionListener(getSelectionListener());
+		// delete toolbar item
+		deleteItem = new ToolItem(toolBar, SWT.PUSH);
+		deleteItem.setImage(IMG_DEL);
+		deleteItem.setToolTipText(DEL_STR);
+		deleteItem.addSelectionListener(getSelectionListener());
+		// edit toolbar item
+		editItem = new ToolItem(toolBar, SWT.PUSH);
+		editItem.setImage(IMG_EDIT);
+		editItem.setToolTipText(EDIT_STR);
+		editItem.addSelectionListener(getSelectionListener());
+		// moveup toolbar item
+		moveUpItem = new ToolItem(toolBar, SWT.PUSH);
+		moveUpItem.setImage(IMG_MOVEUP);
+		moveUpItem.setToolTipText(MOVEUP_STR);
+		moveUpItem.addSelectionListener(getSelectionListener());
+		// movedown toolbar item
+		moveDownItem = new ToolItem(toolBar, SWT.PUSH);
+		moveDownItem.setImage(IMG_MOVEDOWN);
+		moveDownItem.setToolTipText(MOVEDOWN_STR);
+		moveDownItem.addSelectionListener(getSelectionListener());
+		grid3 = new GridData(GridData.FILL_HORIZONTAL
+				| GridData.HORIZONTAL_ALIGN_END);
+		buttonPanel.setLayoutData(grid3);
+		// list control
+		list = new List(filePanel, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
+		grid4 = new GridData(GridData.FILL_BOTH);
+		grid4.heightHint = 38;
+		grid4.horizontalSpan = 2;
+		list.setLayoutData(grid4);
+		list.addSelectionListener(getSelectionListener());
+		selectionChanged();
+	}
+	/**
+	 * Set list values
+	 * 
+	 * @param listVal
+	 */
+	public void setList(String[] listVal) {
+		if (list != null) {
+			list.removeAll();
+		}
+		for (int i = 0; i < listVal.length; i++) {
+			list.add(listVal[i]);
+		}
+	}
+	/**
+	 * Set selection
+	 * 
+	 * @param sel
+	 */
+	public void setSelection(int sel) {
+		if (list.getItemCount() > 0)
+			list.setSelection(sel);
+		selectionChanged();
+	}
+	/**
+	 * Set default selection
+	 */
+	public void setSelection() {
+		if (list.getItemCount() > 0)
+			list.setSelection(0);
+	}
+	/**
+	 * removes all items from list control
+	 */
+	public void removeAll() {
+		if (list != null)
+			list.removeAll();
+	}
+	/**
+	 * get list items
+	 * 
+	 * @return
+	 */
+	public String[] getItems() {
+		return list.getItems();
+	}
+	/**
+	 * Create selection listener for buttons
+	 */
+	private void createSelectionListener() {
+		selectionListener = new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent event) {
+				Widget widget = event.widget;
+				if (widget == addItem) {
+					addPressed();
+				} else if (widget == deleteItem) {
+					removePressed();
+				} else if (widget == moveUpItem) {
+					upPressed();
+				} else if (widget == moveDownItem) {
+					downPressed();
+				} else if (widget == list) {
+					selectionChanged();
+				} else if (widget == editItem) {
+					editSelection();
+				}
+			}
+		};
+	}
+	/**
+	 * Returns selection listener
+	 * 
+	 * @return
+	 */
+	private SelectionListener getSelectionListener() {
+		if (selectionListener == null)
+			createSelectionListener();
+		return selectionListener;
+	}
+	/**
+	 * This method will be called when the add button is pressed
+	 */
+	private void addPressed() {
+		if (type == FILE_DIALOG) {
+			String dialogTitle = ManagedBuilderUIPlugin.getResourceString("FileListControl.filedialog.title"); //$NON-NLS-1$
+			FileDialog dialog = new FileDialog(list.getShell(), SWT.OPEN);
+			dialog.setText(dialogTitle);
+			String selectedFile = dialog.open();
+			if (selectedFile != null)
+				list.add(selectedFile);
+			list.setSelection(list.getItemCount() - 1);
+		} else if (type == TEXT_DIALOG) {
+			// Prompt user for a new item
+			String input = getNewInputObject();
+			// Add it to the list
+			if (input != null) {
+				int index = list.getSelectionIndex();
+				if (index >= 0) {
+					list.add(input, index + 1);
+					list.setSelection(index + 1);
+				} else {
+					list.add(input, 0);
+					list.setSelection(0);
+				}
+				selectionChanged();
+			}
+		} else if (type == DIR_DIALOG) {
+			String dialogText = ManagedBuilderUIPlugin.getResourceString("FileListControl.dirdialog.title"); //$NON-NLS-1$
+			String dialogMessage = ManagedBuilderUIPlugin.getResourceString("FileListControl.dirdialog.desc"); //$NON-NLS-1$
+			DirectoryDialog dialog = new DirectoryDialog(list.getShell(),
+					SWT.OPEN);
+			dialog.setText(dialogText);
+			dialog.setMessage(dialogMessage);
+			String selectedFolder = dialog.open();
+			String selectedPath = ""; //$NON-NLS-1$
+			if (selectedFolder != null) {
+				selectedPath = new Path(selectedFolder).toString();
+				list.add(selectedPath);
+			}
+		}
+		selectionChanged();
+	}
+	/**
+	 * This method will be called when the remove button is pressed
+	 */
+	private void removePressed() {
+		int index = list.getSelectionIndex();
+		if (type == DIR_DIALOG) {
+			String quest = ManagedBuilderUIPlugin.getResourceString("FileListControl.deletedialog.message"); //$NON-NLS-1$
+			String title = ManagedBuilderUIPlugin.getResourceString("FileListControl.deletedialog.title"); //$NON-NLS-1$
+			boolean delDir = MessageDialog.openQuestion(list.getShell(), title,
+					quest);
+			if (delDir && index != -1)
+				list.remove(index);
+		} else if (index != -1)
+			list.remove(index);
+		selectionChanged();
+	}
+	/**
+	 * This method will be called when the move up button is pressed
+	 */
+	private void upPressed() {
+		int index = list.getSelectionIndex();
+		String curSelList = list.getItem(index);
+		String preList = list.getItem(index - 1);
+		list.setItem(index - 1, curSelList);
+		list.setItem(index, preList);
+		list.setSelection(index - 1);
+		selectionChanged();
+	}
+	/**
+	 * This method will be called when the move down button is pressed
+	 */
+	private void downPressed() {
+		int index = list.getSelectionIndex();
+		String curSelList = list.getItem(index);
+		String nextList = list.getItem(index + 1);
+		list.setItem(index + 1, curSelList);
+		list.setItem(index, nextList);
+		list.setSelection(index + 1);
+		selectionChanged();
+	}
+	/**
+	 * This method will be called when the edit button is pressed
+	 */
+	private void editSelection() {
+		int index = list.getSelectionIndex();
+		if (index != -1) {
+			String selItem = list.getItem(index);
+			String title = ManagedBuilderUIPlugin.getResourceString("FileListControl.editdialog.title"); //$NON-NLS-1$
+			if (selItem != null) {
+				InputDialog dialog = new InputDialog(null, title, compTitle,
+						selItem, null);
+				String newItem = null;
+				if (dialog.open() == InputDialog.OK) {
+					newItem = dialog.getValue();
+					if (newItem != null && !newItem.equals(selItem)) {
+						list.setItem(index, newItem);
+						selectionChanged();
+					}
+				}
+			}
+		}
+	}
+	/**
+	 * This method will be called when the list selection changed
+	 */
+	public void selectionChanged() {
+		int index = list.getSelectionIndex();
+		int size = list.getItemCount();
+		deleteItem.setEnabled(size > 0);
+		moveUpItem.setEnabled(size > 1 && index > 0);
+		moveDownItem.setEnabled(size > 1 && index >= 0 && index < size - 1);
+		editItem.setEnabled(size > 0);
+	}
+	/**
+	 * Returns List control
+	 * 
+	 * @return
+	 */
+	public List getListControl() {
+		return list;
+	}
+
+	/**
+	 * Set type
+	 */
+	public void setType(int type) {
+		this.type = type;
+	}
+
+	/**
+	 * Returns the input dialog string
+	 * 
+	 * @return
+	 */
+	private String getNewInputObject() {
+		// Create a dialog to prompt for a new symbol or path
+		String title = ManagedBuilderUIPlugin.getResourceString("FileListControl.newdialog.title"); //$NON-NLS-1$
+		InputDialog dialog = new InputDialog(list.getShell(), title,
+				this.compTitle, new String(), null);
+		String input = null;
+		if (dialog.open() == InputDialog.OK) {
+			input = dialog.getValue();
+			return input.length() == 0 ? null : input;
+		} else
+			return null;
+	}
+}
Index: src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java
===================================================================
RCS file: src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java
diff -N src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/managedbuilder/ui/properties/FileListControlFieldEditor.java	6 Apr 2004 05:12:19 -0000
@@ -0,0 +1,208 @@
+package org.eclipse.cdt.managedbuilder.ui.properties;
+
+/**********************************************************************
+ * Copyright (c) 2004 BitMethods Inc and others.
+ * All rights reserved.   This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ * 
+ * Contributors: 
+ * BitMethods Inc - Initial API and implementation
+ ***********************************************************************/
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.List;
+
+/**
+ * Field editor that uses FileListControl for user input.
+ */
+
+public class FileListControlFieldEditor extends FieldEditor {
+
+	// file list control
+	private FileListControl list;
+	private int type;
+	private GridLayout layout;
+	private static final String DEFAULT_SEPERATOR = ";"; //$NON-NLS-1$
+
+	//values
+	private String[] values = null;
+
+	/**
+	 * Creates a file list control field editor.
+	 * @param name the name of the preference this field editor works on
+	 * @param labelText the label text of the field editor
+	 * @param parent the parent of the field editor's control
+	 * @param type the type of the file list control
+	 */
+	public FileListControlFieldEditor(
+		String name,
+		String labelText,
+		Composite parent,
+		int type) {
+		super(name, labelText, parent);
+		this.type = type;
+		list.setType(type);
+	}
+
+	/**
+	 * Creates a file list control field editor.
+	 * @param name the name of the preference this field editor works on
+	 * @param labelText the label text of the field editor
+	 * @param parent the parent of the field editor's control
+	 * @param value the field editor's value
+	 * @param type the type of the file list control
+	 */
+	public FileListControlFieldEditor(
+		String name,
+		String labelText,
+		Composite parent,
+		String value,
+		int type) {
+		super(name, labelText, parent);
+		this.type = type;
+		this.values = parseString(value);
+		list.setType(type);
+	}
+
+	/**
+	 * Fills this field editor's basic controls into the given parent.
+	 */
+	protected void doFillIntoGrid(Composite parent, int numColumns) {
+		Composite topLayout = new Composite(parent, SWT.NONE);
+		layout = new GridLayout();
+		layout.numColumns = numColumns;
+		layout.marginWidth = 7;
+		layout.marginHeight = 5;
+		layout.makeColumnsEqualWidth = false;
+		topLayout.setLayout(layout);
+		GridData gddata = new GridData(GridData.FILL_HORIZONTAL);
+		gddata.horizontalSpan = 2;
+		topLayout.setLayoutData(gddata);
+		// file list control
+		list =
+			new FileListControl(
+				topLayout,
+				getLabelText(),
+				getType());
+		topLayout.setLayout(layout);
+	}
+
+	/**
+	 * Returns the type of this field editor's file list control
+	 * @return
+	 */
+	private int getType() {
+		return type;
+	}
+
+	/**
+	 * Returns the file list control 
+	 * @return
+	 */
+	protected List getListControl() {
+		return list.getListControl();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.jface.preference.FieldEditor#doLoad()
+	 */
+	protected void doLoad() {
+		if (list != null) {
+			String s = getPreferenceStore().getString(getPreferenceName());
+			String[] array = parseString(s);
+			list.setList(array);
+			list.setSelection(0);
+		}
+		list.selectionChanged();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.jface.preference.FieldEditor#doLoadDefault()
+	 */
+	protected void doLoadDefault() {
+		if (list != null) {
+			list.removeAll();
+			String s =
+				getPreferenceStore().getDefaultString(getPreferenceName());
+			String[] array = parseString(s);
+			list.setList(array);
+			list.selectionChanged();
+		}
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.jface.preference.FieldEditor#doStore()
+	 */
+	protected void doStore() {
+		String s = createList(list.getItems());
+		if (s != null)
+			getPreferenceStore().setValue(getPreferenceName(), s);
+	}
+
+	/**
+	* Returns the number of basic controls this field editor consists of.
+	*
+	* @return the number of controls
+	*/
+	public int getNumberOfControls() {
+		return 1;
+	}
+
+	/**
+	 * Answers a <code>String</code> containing the strings passed in the 
+	 * argument separated by the DEFAULT_SEPERATOR
+	 * 
+	 * @param items An array of strings
+	 * @return 
+	 */
+	private String createList(String[] items) {
+		StringBuffer path = new StringBuffer(""); //$NON-NLS-1$
+
+		for (int i = 0; i < items.length; i++) {
+			path.append(items[i]);
+			if (i < (items.length - 1)) {
+				path.append(DEFAULT_SEPERATOR);
+			}
+		}
+		return path.toString();
+	}
+
+	/**
+	 * Parse the string with the separator and returns the string array. 
+	 * @param stringList
+	 * @return
+	 */
+	private String[] parseString(String stringList) {
+		StringTokenizer tokenizer =
+			new StringTokenizer(stringList, DEFAULT_SEPERATOR);
+		ArrayList list = new ArrayList();
+		while (tokenizer.hasMoreElements()) {
+			list.add(tokenizer.nextElement());
+		}
+		return (String[]) list.toArray(new String[list.size()]);
+	}
+
+	/**
+	 * Set style
+	 */
+	public void setStyle() {
+		layout.marginWidth = 0;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.jface.preference.FieldEditor#adjustForNumColumns(int)
+	 */
+	protected void adjustForNumColumns(int numColumns) {
+
+	}
+
+}
\ No newline at end of file

Attachment: ModifiedCode.zip
Description: Zip compressed data


Back to the top