Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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.eclipse.ant.internal.ui.launchConfigurations;
 
 
 import java.util.List;
 import  org.eclipse.swt.SWT;
 import  org.eclipse.swt.events.SelectionAdapter;
 import  org.eclipse.swt.events.SelectionEvent;
 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.Label;
 import  org.eclipse.swt.widgets.Shell;
 import  org.eclipse.swt.widgets.Table;
Dialog to specify target execution order
 
 public class TargetOrderDialog extends Dialog implements ISelectionChangedListener {
 	
 	private Button fUp;
 	private Button fDown;
 	private TableViewer fViewer;
 	private Object[] fTargets;

Constructs the dialog.

Parameters:
parentShell
 
 	public TargetOrderDialog(Shell parentShellObject[] targets) {
 		super(parentShell);
 		 = targets;
 	}
 
 	/* (non-Javadoc)
 	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 	 */
 	protected Control createDialogArea(Composite parent) {
 		
 		Composite comp = (Composite)super.createDialogArea(parent);
 		((GridLayout)comp.getLayout()).numColumns= 2;
 		Label label = new Label(comp, SWT.NONE);
 		label.setFont(comp.getFont());
 		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
 		gd.horizontalSpan = 2;
 		label.setLayoutData(gd);		
 		
 		
 		createButtons(comp);
 		
 		
 		return comp;
 	}

Create button area & buttons

Parameters:
comp
 
 	private void createButtons(Composite parent) {
 		Composite comp = new Composite(parent, SWT.NONE);
 		GridLayout layout = new GridLayout();
 		layout.marginHeight= 0;
 		layout.marginWidth= 0;
 		GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
 		gd.verticalAlignment = GridData.BEGINNING;
 		comp.setLayout(layout);
 		comp.setLayoutData(gd);
 		
 		 = new Button(comp, SWT.PUSH);
 		.setFont(parent.getFont());
		.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
			}
		});
		 = new Button(comp, SWT.PUSH);
		.setFont(parent.getFont());
		.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
			}
		});
	}
	private void handleDownPressed() {
		List targets = getOrderedSelection();
		if (targets.isEmpty()) {
			return;
		}
		List listnew ArrayList(Arrays.asList());
		int bottom = list.size() - 1;
		int index = 0;
		for (int i = targets.size() - 1; i >= 0; i--) {
			Object target = targets.get(i);
			index = list.indexOf(target);
			if (index < bottom) {
				bottom = index + 1;
				Object temp = list.get(bottom);
				list.set(bottomtarget);
				list.set(indextemp);
			}
			bottom = index;
	}
	private void handleUpPressed() {
		List targets = getOrderedSelection();
		if (targets.isEmpty()) {
			return;
		}
		int top = 0;
		int index = 0;
		List listnew ArrayList(Arrays.asList());
		Iterator entries = targets.iterator();
		while (entries.hasNext()) {
			Object target = entries.next();
			index = list.indexOf(target);
			if (index > top) {
				top = index - 1;
				Object temp = list.get(top);
				list.set(toptarget);
				list.set(indextemp);
			}
			top = index;
	}

Updates the entries to the entries in the given list
	private void setEntries(List list) {
		list.toArray();
		// update all selection listeners
	}

Returns the selected items in the list, in the order they are displayed (not in the order they were selected).

Returns:
targets for an action
		List targets = new ArrayList();
		Object[] entries = ;
		for (int i = 0; i < entries.lengthi++) {
			Object target = entries[i];
			if (selection.contains(target)) {
				targets.add(target);
			}
		}
		return targets;		
	}

Creates a list viewer for the targets

Parameters:
comp
	private void createTargetList(Composite comp) {
		 = new TableViewer(comp, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
		Table table = .getTable();
		GridData gd = new GridData(GridData.FILL_BOTH);
		gd.heightHint = 200;
		gd.widthHint = 250;		
		table.setLayoutData(gd);
		table.setFont(comp.getFont());
	}

Returns the ordered targets
	public Object[] getTargets() {
		return ;
	}

Update button enablement

See also:
org.eclipse.jface.viewers.ISelectionChangedListener.selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
	public void selectionChanged(SelectionChangedEvent event) {
	}
	private void updateButtons() {
		int[] selections = .getTable().getSelectionIndices();
		int last = . - 1;
		boolean up = true && selections.length > 0;
		boolean down = true && selections.length > 0;
		for (int i = 0; i < selections.lengthi++) {
			if (selections[i] == 0) {
				up = false;
			}
			if (selections[i] == last) {
				down = false;
			}
		}
		.setEnabled(up);
		.setEnabled(down);		
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
	 */
	protected void configureShell(Shell shell) {
		super.configureShell(shell);
	}
New to GrepCode? Check out our FAQ X