krysalis-version/src/java/org/krysalis/version/eclipse/plugin/property ConstraintPreferencePage.java,NONE,1.1 AdaptableList.java,NONE,1.1 DirtyStateContribution.java,NONE,1.1 MarkElementProperties.java,NONE,1.1

[email protected] Fri, 21 Mar 2003 15:33:01 -0800
Newsgroups gmane.comp.krysalis.sandbox
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/eclipse/plugin/property
In directory sc8-pr-cvs1:/tmp/cvs-serv22996/src/java/org/krysalis/version/eclipse/plugin/property

Added Files:
	ConstraintPreferencePage.java AdaptableList.java 
	DirtyStateContribution.java MarkElementProperties.java 
Log Message:
Constraint changes

--- NEW FILE: ConstraintPreferencePage.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Patchy         *
 * Software License version 1.1_01, a copy of which has been included        *
 * at the bottom of this file.                                               *
 *****************************************************************************/
package org.krysalis.version.eclipse.plugin.property;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
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;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.help.WorkbenchHelp;
import org.krysalis.version.eclipse.plugin.VersionPlugin;
import org.krysalis.version.eclipse.plugin.util.IConstraintConstants;
import org.krysalis.version.eclipse.plugin.util.MessageUtil;

/**
 * This class implements a sample preference page that is 
 * added to the preference dialog based on the registration.
 */
public class ConstraintPreferencePage
	extends PreferencePage
	implements IWorkbenchPreferencePage, SelectionListener, ModifyListener
{
	private Button radioButton1;
	private Button radioButton2;
	private Button radioButton3;

	private Button checkBox1;
	private Button checkBox2;
	private Button checkBox3;

	private Text textField;

	private Button pushButton_textField;
	/**
	 * Creates an new checkbox instance and sets the default
	 * layout data.
	 *
	 * @param group  the composite in which to create the checkbox
	 * @param label  the string to set into the checkbox
	 * @return the new checkbox
	 */
	private Button createCheckBox(Composite group, String label)
	{
		Button button = new Button(group, SWT.CHECK | SWT.LEFT);
		button.setText(label);
		button.addSelectionListener(this);
		GridData data = new GridData();
		button.setLayoutData(data);
		return button;
	}
	/**
	 * Creates composite control and sets the default layout data.
	 *
	 * @param parent  the parent of the new composite
	 * @param numColumns  the number of columns for the new composite
	 * @return the newly-created coposite
	 */
	private Composite createComposite(Composite parent, int numColumns)
	{
		Composite composite = new Composite(parent, SWT.NULL);

		//GridLayout
		GridLayout layout = new GridLayout();
		layout.numColumns = numColumns;
		composite.setLayout(layout);

		//GridData
		GridData data = new GridData();
		data.verticalAlignment = GridData.FILL;
		data.horizontalAlignment = GridData.FILL;
		composite.setLayoutData(data);
		return composite;
	}
	/** (non-Javadoc)
	 * Method declared on PreferencePage
	 */
	protected Control createContents(Composite parent)
	{
		WorkbenchHelp.setHelp(parent, IConstraintConstants.PREFERENCE_PAGE_CONTEXT);

		//composite_textField << parent
		Composite composite_textField = createComposite(parent, 2);
		Label label_textField = createLabel(composite_textField, MessageUtil.getString("Text_Field")); //$NON-NLS-1$
		textField = createTextField(composite_textField);
		pushButton_textField = createPushButton(composite_textField, MessageUtil.getString("Change")); //$NON-NLS-1$

		//composite_tab << parent
		Composite composite_tab = createComposite(parent, 2);
		Label label1 = createLabel(composite_tab, MessageUtil.getString("Radio_Button_Options")); //$NON-NLS-1$

		//
		tabForward(composite_tab);
		//radio button composite << tab composite
		Composite composite_radioButton = createComposite(composite_tab, 1);
		radioButton1 = createRadioButton(composite_radioButton, MessageUtil.getString("Radio_button_1")); //$NON-NLS-1$
		radioButton2 = createRadioButton(composite_radioButton, MessageUtil.getString("Radio_button_2")); //$NON-NLS-1$
		radioButton3 = createRadioButton(composite_radioButton, MessageUtil.getString("Radio_button_3")); //$NON-NLS-1$

		//composite_tab2 << parent
		Composite composite_tab2 = createComposite(parent, 2);
		Label label2 = createLabel(composite_tab2, MessageUtil.getString("Check_Box_Options")); //$NON-NLS-1$

		//
		tabForward(composite_tab2);
		//composite_checkBox << composite_tab2
		Composite composite_checkBox = createComposite(composite_tab2, 1);
		checkBox1 = createCheckBox(composite_checkBox, MessageUtil.getString("Check_box_1")); //$NON-NLS-1$
		checkBox2 = createCheckBox(composite_checkBox, MessageUtil.getString("Check_box_2")); //$NON-NLS-1$
		checkBox3 = createCheckBox(composite_checkBox, MessageUtil.getString("Check_box_3")); //$NON-NLS-1$

		initializeValues();

		//font = null;
		return new Composite(parent, SWT.NULL);
	}
	/**
	 * Utility method that creates a label instance
	 * and sets the default layout data.
	 *
	 * @param parent  the parent for the new label
	 * @param text  the text for the new label
	 * @return the new label
	 */
	private Label createLabel(Composite parent, String text)
	{
		Label label = new Label(parent, SWT.LEFT);
		label.setText(text);
		GridData data = new GridData();
		data.horizontalSpan = 2;
		data.horizontalAlignment = GridData.FILL;
		label.setLayoutData(data);
		return label;
	}
	/**
	 * Utility method that creates a push button instance
	 * and sets the default layout data.
	 *
	 * @param parent  the parent for the new button
	 * @param label  the label for the new button
	 * @return the newly-created button
	 */
	private Button createPushButton(Composite parent, String label)
	{
		Button button = new Button(parent, SWT.PUSH);
		button.setText(label);
		button.addSelectionListener(this);
		GridData data = new GridData();
		data.horizontalAlignment = GridData.FILL;
		button.setLayoutData(data);
		return button;
	}
	/**
	 * Utility method that creates a radio button instance
	 * and sets the default layout data.
	 *
	 * @param parent  the parent for the new button
	 * @param label  the label for the new button
	 * @return the newly-created button
	 */
	private Button createRadioButton(Composite parent, String label)
	{
		Button button = new Button(parent, SWT.RADIO | SWT.LEFT);
		button.setText(label);
		button.addSelectionListener(this);
		GridData data = new GridData();
		button.setLayoutData(data);
		return button;
	}
	/**
	 * Create a text field specific for this application
	 *
	 * @param parent  the parent of the new text field
	 * @return the new text field
	 */
	private Text createTextField(Composite parent)
	{
		Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
		text.addModifyListener(this);
		GridData data = new GridData();
		data.horizontalAlignment = GridData.FILL;
		data.grabExcessHorizontalSpace = true;
		data.verticalAlignment = GridData.CENTER;
		data.grabExcessVerticalSpace = false;
		text.setLayoutData(data);
		return text;
	}
	/** 
	 * The <code>ConstraintPreferencePage</code> implementation of this
	 * <code>PreferencePage</code> method 
	 * returns preference store that belongs to the our plugin.
	 * This is important because we want to store
	 * our preferences separately from the desktop.
	 */
	protected IPreferenceStore doGetPreferenceStore()
	{
		return VersionPlugin.getDefault().getPreferenceStore();
	}
	/* (non-Javadoc)
	 * Method declared on IWorkbenchPreferencePage
	 */
	public void init(IWorkbench workbench)
	{
	}
	/**
	 * Initializes states of the controls using default values
	 * in the preference store.
	 */
	private void initializeDefaults()
	{
		IPreferenceStore store = getPreferenceStore();
		checkBox1.setSelection(store.getDefaultBoolean(IConstraintConstants.PRE_CHECK1));
		checkBox2.setSelection(store.getDefaultBoolean(IConstraintConstants.PRE_CHECK2));
		checkBox3.setSelection(store.getDefaultBoolean(IConstraintConstants.PRE_CHECK3));

		radioButton1.setSelection(false);
		radioButton2.setSelection(false);
		radioButton3.setSelection(false);
		int choice = store.getDefaultInt(IConstraintConstants.PRE_RADIO_CHOICE);
		switch (choice)
		{
			case 1 :
				radioButton1.setSelection(true);
				break;
			case 2 :
				radioButton2.setSelection(true);
				break;
			case 3 :
				radioButton3.setSelection(true);
				break;
		}
		textField.setText(store.getDefaultString(IConstraintConstants.PRE_TEXT));
	}
	/**
	 * Initializes states of the controls from the preference store.
	 */
	private void initializeValues()
	{
		IPreferenceStore store = getPreferenceStore();
		checkBox1.setSelection(store.getBoolean(IConstraintConstants.PRE_CHECK1));
		checkBox2.setSelection(store.getBoolean(IConstraintConstants.PRE_CHECK2));
		checkBox3.setSelection(store.getBoolean(IConstraintConstants.PRE_CHECK3));

		int choice = store.getInt(IConstraintConstants.PRE_RADIO_CHOICE);
		switch (choice)
		{
			case 1 :
				radioButton1.setSelection(true);
				break;
			case 2 :
				radioButton2.setSelection(true);
				break;
			case 3 :
				radioButton3.setSelection(true);
				break;
		}
		textField.setText(store.getString(IConstraintConstants.PRE_TEXT));
	}
	/** (non-Javadoc)
	 * Method declared on ModifyListener
	 */
	public void modifyText(ModifyEvent event)
	{
		//Do nothing on a modification in this example
	}
	/* (non-Javadoc)
	 * Method declared on PreferencePage
	 */
	protected void performDefaults()
	{
		super.performDefaults();
		initializeDefaults();
	}
	/* (non-Javadoc)
	 * Method declared on PreferencePage
	 */
	public boolean performOk()
	{
		storeValues();
		VersionPlugin.getDefault().savePluginPreferences();
		return true;
	}
	/**
	 * Stores the values of the controls back to the preference store.
	 */
	private void storeValues()
	{
		IPreferenceStore store = getPreferenceStore();
		store.setValue(IConstraintConstants.PRE_CHECK1, checkBox1.getSelection());
		store.setValue(IConstraintConstants.PRE_CHECK2, checkBox2.getSelection());
		store.setValue(IConstraintConstants.PRE_CHECK3, checkBox3.getSelection());

		int choice = 1;

		if (radioButton2.getSelection())
			choice = 2;
		else if (radioButton3.getSelection())
			choice = 3;

		store.setValue(IConstraintConstants.PRE_RADIO_CHOICE, choice);
		store.setValue(IConstraintConstants.PRE_TEXT, textField.getText());
	}
	/**
	 * Creates a tab of one horizontal spans.
	 *
	 * @param parent  the parent in which the tab should be created
	 */
	private void tabForward(Composite parent)
	{
		Label vfiller = new Label(parent, SWT.LEFT);
		GridData gridData = new GridData();
		gridData = new GridData();
		gridData.horizontalAlignment = GridData.BEGINNING;
		gridData.grabExcessHorizontalSpace = false;
		gridData.verticalAlignment = GridData.CENTER;
		gridData.grabExcessVerticalSpace = false;
		vfiller.setLayoutData(gridData);
	}
	/** (non-Javadoc)
	 * Method declared on SelectionListener
	 */
	public void widgetDefaultSelected(SelectionEvent event)
	{
		//Handle a default selection. Do nothing in this example
	}
	/** (non-Javadoc)
	 * Method declared on SelectionListener
	 */
	public void widgetSelected(SelectionEvent event)
	{
		//Do nothing on selection in this example;
	}
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003  Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
   "This product includes software developed for project 
	Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
individuals, who decided to donate the code to this project in
respect of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/
--- NEW FILE: AdaptableList.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Patchy         *
 * Software License version 1.1_01, a copy of which has been included        *
 * at the bottom of this file.                                               *
 *****************************************************************************/
package org.krysalis.version.eclipse.plugin.property;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.model.IWorkbenchAdapter;

/**
 * A list of adaptable objects.  This is a generic list that can
 * be used to display an arbitrary set of adaptable objects in the workbench.
 * Also implements the IWorkbenchAdapter interface for simple display
 * and navigation.
 */
public class AdaptableList implements IWorkbenchAdapter, IAdaptable
{
	protected List children = new ArrayList();
	/**
	 * Creates a new adaptable list with the given children.
	 */
	public AdaptableList()
	{
	}
	/**
	 * Creates a new adaptable list with the given children.
	 */
	public AdaptableList(IAdaptable[] newChildren)
	{
		for (int i = 0; i < newChildren.length; i++)
		{
			children.add(newChildren[i]);
		}
	}
	/**
	 * Adds all the adaptable objects in the given enumeration to this list.
	 * Returns this list.
	 */
	public AdaptableList add(Iterator iterator)
	{
		while (iterator.hasNext())
		{
			add((IAdaptable) iterator.next());
		}
		return this;
	}
	/**
	 * Adds the given adaptable object to this list.
	 * Returns this list.
	 */
	public AdaptableList add(IAdaptable adaptable)
	{
		children.add(adaptable);
		return this;
	}
	/* (non-Javadoc)
	 * Method declared on IAdaptable
	 */
	public Object getAdapter(Class adapter)
	{
		if (adapter == IWorkbenchAdapter.class)
			return this;
		return null;
	}
	/**
	 * Returns the elements in this list.
	 */
	public Object[] getChildren()
	{
		return children.toArray();
	}
	/* (non-Javadoc)
	 * Method declared on IWorkbenchAdapter
	 */
	public Object[] getChildren(Object o)
	{
		return children.toArray();
	}
	/* (non-Javadoc)
	 * Method declared on IWorkbenchAdapter
	 */
	public ImageDescriptor getImageDescriptor(Object object)
	{
		return null;
	}
	/* (non-Javadoc)
	 * Method declared on IWorkbenchAdapter
	 */
	public String getLabel(Object object)
	{
		return object == null ? "" : object.toString(); //$NON-NLS-1$
	}
	/* (non-Javadoc)
	 * Method declared on IWorkbenchAdapter
	 */
	public Object getParent(Object object)
	{
		return null;
	}
	/**
	 * Removes the given adaptable object from this list.
	 */
	public void remove(IAdaptable adaptable)
	{
		children.remove(adaptable);
	}
	/**
	 * Returns the number of items in the list
	 */
	public int size()
	{
		return children.size();
	}
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003  Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
   "This product includes software developed for project 
	Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
individuals, who decided to donate the code to this project in
respect of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/
--- NEW FILE: DirtyStateContribution.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Patchy         *
 * Software License version 1.1_01, a copy of which has been included        *
 * at the bottom of this file.                                               *
 *****************************************************************************/
package org.krysalis.version.eclipse.plugin.property;

import org.eclipse.jface.action.ControlContribution;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPropertyListener;

import org.krysalis.version.eclipse.plugin.util.MessageUtil;

/**
 * This class demonstrates the contribution of a custom control to the 
 * status line for the constraint editor.  The control shows the
 * dirty status of the editor.
 */
public class DirtyStateContribution extends ControlContribution implements IPropertyListener
{
	private Composite composite;
	private Label label;
	private IEditorPart activeEditor;
	/**
	 * Creates a new DirtyStateContribution.
	 */
	public DirtyStateContribution()
	{
		super("DirtyState"); //$NON-NLS-1$
	}
	/* (non-Javadoc)
	 * Method declared on ControlContribution
	 */
	public Control createControl(Composite parent)
	{
		// If the composite is good just return it.
		if (composite != null && !composite.isDisposed())
			return composite;

		// Create composite for border.
		composite = new Composite(parent, SWT.BORDER);
		composite.setData(this);

		// Create label inside composite.	
		label = new Label(composite, SWT.NONE);
		label.setSize(80, 15);

		updateState();
		return composite;
	}
	/**
	 * Called when an editor is activated.
	 *
	 * @see constraintEditorActionBarContributor#setActiveEditor(IEditorPart)
	 */
	public void editorChanged(IEditorPart part)
	{
		if (activeEditor != null)
		{
			activeEditor.removePropertyListener(this);
		}
		activeEditor = part;
		if (activeEditor != null)
		{
			activeEditor.addPropertyListener(this);
		}
		updateState();
	}
	/* (non-Javadoc)
	 * Method declared on IPropertyListener
	 */
	public void propertyChanged(Object source, int propID)
	{
		if (source instanceof IEditorPart)
			updateState();
	}
	/**
	 * Updates the state of the label.
	 */
	private void updateState()
	{
		if (label == null || label.isDisposed())
			return;

		boolean saveNeeded = false;
		if (activeEditor != null)
			saveNeeded = activeEditor.isDirty();
		if (saveNeeded)
			label.setText(MessageUtil.getString("Save_Needed")); //$NON-NLS-1$
		else
			label.setText(MessageUtil.getString("Clean")); //$NON-NLS-1$
	}
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003  Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
   "This product includes software developed for project 
	Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
individuals, who decided to donate the code to this project in
respect of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/
--- NEW FILE: MarkElementProperties.java ---
/*****************************************************************************
 * Copyright (C) The Krysalis project. All rights reserved.                  *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Krysalis Patchy         *
 * Software License version 1.1_01, a copy of which has been included        *
 * at the bottom of this file.                                               *
 *****************************************************************************/
package org.krysalis.version.eclipse.plugin.property;

import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.krysalis.version.eclipse.plugin.util.MessageUtil;
 
import org.krysalis.version.eclipse.plugin.util.MarkElement;
/**
 * This class encapsulates property sheet properties
 * for MarkElement.  This will display properties for
 * the MarkElement when selected in the constraint editor's
 * content outline.
 */
public class MarkElementProperties implements IPropertySource
{
	protected MarkElement element;

	protected static final String PROPERTY_LINECOUNT = "lineno"; //$NON-NLS-1$
	protected static final String PROPERTY_START = "start"; //$NON-NLS-1$
	protected static final String PROPERTY_LENGTH = "length"; //$NON-NLS-1$
	/**
	 * Creates a new MarkElementProperties.
	 *
	 * @param element  the element whose properties this instance represents
	 */
	public MarkElementProperties(MarkElement element)
	{
		super();
		this.element = element;
	}
	/* (non-Javadoc)
	 * Method declared on IPropertySource
	 */
	public Object getEditableValue()
	{
		return this;
	}
	/* (non-Javadoc)
	 * Method declared on IPropertySource
	 */
	public IPropertyDescriptor[] getPropertyDescriptors()
	{
		// Create the property vector.
		IPropertyDescriptor[] propertyDescriptors = new IPropertyDescriptor[3];

		// Add each property supported.
		PropertyDescriptor descriptor;

		descriptor = new PropertyDescriptor(PROPERTY_LINECOUNT, MessageUtil.getString("Line_count")); //$NON-NLS-1$
		propertyDescriptors[0] = descriptor;
		descriptor = new PropertyDescriptor(PROPERTY_START, MessageUtil.getString("Title_start")); //$NON-NLS-1$
		propertyDescriptors[1] = descriptor;
		descriptor = new PropertyDescriptor(PROPERTY_LENGTH, MessageUtil.getString("Title_length")); //$NON-NLS-1$
		propertyDescriptors[2] = descriptor;

		// Return it.
		return propertyDescriptors;
	}
	/* (non-Javadoc)
	 * Method declared on IPropertySource
	 */
	public Object getPropertyValue(Object name)
	{
		if (name.equals(PROPERTY_LINECOUNT))
			return new Integer(element.getNumberOfLines());
		if (name.equals(PROPERTY_START))
			return new Integer(element.getStart());
		if (name.equals(PROPERTY_LENGTH))
			return new Integer(element.getLength());
		return null;
	}
	/* (non-Javadoc)
	 * Method declared on IPropertySource
	 */
	public boolean isPropertySet(Object property)
	{
		return false;
	}
	/* (non-Javadoc)
	 * Method declared on IPropertySource
	 */
	public void resetPropertyValue(Object property)
	{
	}
	/* (non-Javadoc)
	 * Method declared on IPropertySource
	 */
	public void setPropertyValue(Object name, Object value)
	{
	}
}
/*
The Krysalis Patchy Software License, Version 1.1_01
Copyright (c) 2002-2003  Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

3. The end-user documentation included with the redistribution,
if any, must include the following acknowledgment:
   "This product includes software developed for project 
	Krysalis (http://www.krysalis.org/)."
Alternately, this acknowledgment may appear in the software itself,
if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
"Krysalis Centipede" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
"Krysalis Centipede", nor may "Krysalis" appear in their name,
without prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
individuals, who decided to donate the code to this project in
respect of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE KRYSALIS PROJECT OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================*/



-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open! 
Get cracking and register here for some mind boggling fun and 
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en