Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2011 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.help.ui;
 
 
 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.Text;
Clients that contribute search scope root page to the search engine definition must extend this class and implement createScopeContents method. The page will come preset with the engine name, image and description, as well as the master switch that turns the engine on or off. When the engine master switch is set to false, all the children in the client composite will be disabled.

Since:
3.1
 
 public abstract class RootScopePage extends PreferencePage implements
 	private IEngineDescriptor ed;
 
 	private String scopeSetName;
 
 	private Button masterButton;
 
 	private Text labelText;
 
 	private Text descText;
 
 	private Hashtable disabledStates = new Hashtable();
 
 	private Label spacer;
 
 	private Composite contentContainer;

The default constructor.
 
 	public RootScopePage() {
 	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see ISearchScopePage#init(IEngineDescriptor, String)
 	 */
 	public void init(IEngineDescriptor edString scopeSetName) {
 		this. = ed;
 		this. = scopeSetName;
 	}

Creates the initial contents of the page and allocates the area for the clients. Classes that extend this class should implement createScopeContents(Composite) instead.

Parameters:
parent the page parent
Returns:
the page client control
 
 	protected final Control createContents(Composite parent) {
     	PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
 	     "org.eclipse.help.ui.searchScope"); //$NON-NLS-1$
 		 = new Composite(parent, SWT.NULL);
 		GridLayout layout = new GridLayout();
 		GridData gd;
 		//if (ed.isUserDefined())
 		layout.numColumns = 2;
 		.setLayout(layout);		
 			 = new Button(, SWT.CHECK);
 			gd = new GridData();
 			gd.horizontalSpan = 2;// ed.isUserDefined() ? 2 : 1;
			.setLayoutData(gd);
			 = new Label(, SWT.NULL);
			gd = new GridData();
			gd.horizontalSpan = 2;// ed.isUserDefined() ? 2 : 1;
			.setLayoutData(gd);
			boolean masterValue = getPreferenceStore().getBoolean(ScopeSet.getMasterKey(.getId()));
			.setSelection(masterValue);
			.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
				}
			});
			Label label = new Label(, SWT.NULL);
			 = new Text(, SWT.BORDER);
			gd = new GridData(GridData.FILL_HORIZONTAL);
			gd.widthHint = 200;
			.setLayoutData(gd);
			.setEditable(.isUserDefined());
			label = new Label(, SWT.NULL);
			gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
			label.setLayoutData(gd);
			 = new Text(, SWT.BORDER | SWT.MULTI | SWT.WRAP);
			gd = new GridData(GridData.FILL_HORIZONTAL);
			.setEditable(.isUserDefined());
			gd.widthHint = 200;
			gd.heightHint = 48;
			.setLayoutData(gd);
		}
		// adjust number of columns if needed
		if (ccol > layout.numColumns && isInPreferenceDialog()) {
			layout.numColumns = ccol;
			gd = (GridData) .getLayoutData();
			gd.horizontalSpan = layout.numColumns;
			gd = (GridData) .getLayoutData();
			gd.horizontalSpan = layout.numColumns;
			gd = (GridData) .getLayoutData();
			gd.horizontalSpan = layout.numColumns - 1;
			gd = (GridData) .getLayoutData();
			gd.horizontalSpan = layout.numColumns - 1;
		}
	}

Called when the value of the master switch has changed. The default implementation disables the scope contents control when the master switch is off. Subclass can override this behaviour.

Parameters:
value true if the master switch is on, false otherwise.
	protected void masterValueChanged(boolean value) {
	}
	private void updateEnableState(boolean enabled) {
		Control[] children = .getChildren();
		boolean first = .isEmpty();
		for (int i = 0; i < children.length; i++) {
			Control child = children[i];
			if (child == )
				continue;
			if (!enabled) {
				.put(childnew Boolean(child.isEnabled()));
				child.setEnabled(false);
else {
				Boolean savedState = (Boolean.get(child);
				if (!first)
					child.setEnabled(savedState != null ? savedState
							.booleanValue() : true);
			}
		}
	}

Returns the scope set name passed to the page during initialization.

Returns:
the name of the current scope set
	protected String getScopeSetName() {
		return ;
	}

Returns the descriptor of the engine associated with this page.

Returns:
the engine descriptor
		return ;
	}

Tests whether the search engine has been selected to participate in the search.

Returns:
true if the search engine is enabled, false otherwise.
	protected boolean isEngineEnabled() {
			return true;
		}
		return .getSelection();
	}

Stores the value of the master switch in the preference store. Subclasses may override but must call 'super'.

Returns:
true if the wizard can be closed, false otherwise.
	public boolean performOk() {
		if ( != null) {
			.setLabel(.getText());
		}
		return true;
	}

Sets the value of the master switch to the initial value from the extension. Subclasses may override but must call 'super'.
	protected void performDefaults() {
	}
	private void updateControls(boolean first) {
			boolean value = getPreferenceStore().getBoolean(ScopeSet.getMasterKey(.getId()));
			boolean cvalue = .getSelection();
			if (value != cvalue) {
				.setSelection(value);
else if (first) {
			}
			.setText(.getLabel());
		}
	}
	private boolean isInPreferenceDialog() {
		return getContainer() != null;
	}

Initializes default values of the store to be used when the user presses 'Defaults' button. Subclasses may override but must call 'super'.

Parameters:
store the preference store
	protected void initializeDefaults(IPreferenceStore store) {
		store.setDefault(ScopeSet.getMasterKey(.getId()), value
	}

Abstract method that subclasses must implement in order to provide root page content. The parent uses GridLayout to position and size the widgets. Widgets created in this method should use GridData to configure the way they fit in the overall page.

The common widgets created by this page will set number of columns they need for themselves only. Clients that implement this method should return the required number of columns so that the root page widgets can be adjusted if more columns are needed than initially set.

Parameters:
parent the page parent
Returns:
number of columns required by the client content
	protected abstract int createScopeContents(Composite parent);
New to GrepCode? Check out our FAQ X