Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008 itemis AG (http://www.itemis.eu) 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 /
  
  package org.eclipse.xtext.ui.editor.preferences.fields;
 
 
 import  org.eclipse.jface.preference.FieldEditor;
 import  org.eclipse.jface.preference.IPreferenceStore;
 import  org.eclipse.swt.SWT;
 import  org.eclipse.swt.events.DisposeEvent;
 import  org.eclipse.swt.events.DisposeListener;
 import  org.eclipse.swt.events.SelectionAdapter;
 import  org.eclipse.swt.events.SelectionEvent;
 import  org.eclipse.swt.layout.GridData;
 import  org.eclipse.swt.widgets.Composite;
 import  org.eclipse.swt.widgets.Control;
 import  org.eclipse.swt.widgets.List;

Author(s):
Dennis H´┐Żbner - Initial contribution and API
 
 public abstract class AbstractMasterDetailsFieldEditor extends FieldEditor {
 
 	private List masterList;
 	protected final java.util.List<?> items;
 
 	public AbstractMasterDetailsFieldEditor(String nameString labelText, Composite composite,
 			IPreferenceStore preferenceStorejava.util.List<?> list) {
 		this. = list;
 		init(namelabelText);
 		setPreferenceStore(preferenceStore);
 		createControl(composite);
 	}
 
 	protected void adjustForNumColumns(int numColumns) {
 		Control control = getLabelControl();
 		((GridData) control.getLayoutData()).horizontalSpan = numColumns;
 		((GridData) .getLayoutData()).horizontalSpan = numColumns - 1;
 	}
 
 	protected void doFillIntoGrid(Composite parentint numColumns) {
 		Control control = getLabelControl(parent);
 		GridData gd = new GridData();
 		gd.horizontalSpan = numColumns;
 		control.setLayoutData(gd);
 
 		 = getMasterList(parent);
 		gd = new GridData();
 		gd.verticalAlignment = GridData.FILL;
 		gd.horizontalSpan = numColumns - 1;
 		.setLayoutData(gd);
 
 		gd = new GridData(GridData.FILL_HORIZONTAL);
 		gd.verticalAlignment = GridData.FILL;
 		gd.horizontalSpan = numColumns - 1;
 		gd.grabExcessHorizontalSpace = true;
 		.getControl().setLayoutData(gd);
 	}

Returns:
Detail part of Master-Detail EditorField
 
 	abstract protected AbstractDetailsPart createDetailsPart();
 
 	private List getMasterList(Composite parent) {
 		if ( == null) {
 			 = new List(parent, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL);
 			.setFont(parent.getFont());
 			java.util.List<Stringnames = new ArrayList<String>();
 			for (Object ttd : ) {
 				if (label(ttd) != null)
 					names.add(label(ttd));
 				else
 					names.add("<unnamed> (" + identifier(ttd) + ")");
 			}
 			.setItems(names.toArray(new String[names.size()]));
 			.addSelectionListener(new SelectionAdapter() {
 				public void widgetSelected(SelectionEvent e) {
 					doLoad();
 				}
 			});
 			.addDisposeListener(new DisposeListener() {
 				public void widgetDisposed(DisposeEvent event) {
 					 = null;
				}
			});
			.setSelection(0);
		}
		return ;
	}

Parameters:
object
Returns:
Identifier for given Object
	protected abstract String identifier(Object object);

Parameters:
object
Returns:
Label for given Object
	protected abstract String label(Object object);
	protected void doLoad() {
		if (.getSelectionIndex() == -1) {
			return;
		}
	}
	public void loadDefault() {
		if ( != null) {
			int selectionIndex = .getSelectionIndex();
			super.loadDefault();
			.select(selectionIndex);
else {
			super.loadDefault();
		}
	}
	protected void doLoadDefault() {
		for (Object item : ) {
		}
	}
	protected void doStore() {
	}
	public void store() {
	}
	public int getNumberOfControls() {
		return 2;
	}
	public void setEnabled(boolean enabled, Composite parent) {
		super.setEnabled(enabledparent);
		getMasterList(parent).setEnabled(enabled);
	}
	}
	}

Returns:
selected Object
	private Object selectedObject() {
		int selectionIndex = .getSelectionIndex();
		Object tokenTypeDef = .get(selectionIndex);
		return tokenTypeDef;
	}
New to GrepCode? Check out our FAQ X