/* * Copyright (c) 2006,2009 Declarative Engineering LLC. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Declarative Engineering LLC * verson 1 which accompanies this distribution, and is available at * http://declarativeengineering.com/legal/DE_Developer_License_v1.txt */ package com.foundation.tcv.swt.server; import com.foundation.tcv.swt.ISpinner; import com.foundation.tcv.view.ViewMessage; import com.foundation.view.SingleAssociationContainer; import com.foundation.view.SingleResourceAssociation; public class Spinner extends Component implements ISpinner { /** The progress' maximum resource which bounds the progress states. */ private SingleResourceAssociation maximum = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_INTEGER, false, new Integer(0)); /** The progress' minimum resource which bounds the progress states. */ private SingleResourceAssociation minimum = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_INTEGER, false, new Integer(0)); /** The progress' progress resource which defines the current progress state. */ private SingleResourceAssociation selection = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_INTEGER, true, new Integer(0)); /** The progress' progress resource which defines the increment state. */ private SingleResourceAssociation increment = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_INTEGER, false, new Integer(0)); /** The progress' progress resource which defines the page increment state. */ private SingleResourceAssociation pageIncrement = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_INTEGER, false, new Integer(0)); /** Whether the value is automatically synchronized as the user edits the value. Otherwise the field must be manually synchronized. */ private boolean autoSynchronizeSelection = false; /** The delay used when auto synchronizing the value. A zero value means there will be no delay. The value must be on the range of [0..10,000]. */ private long autoSynchronizeSelectionDelay = 500; /** * Spinner constructor. * @param parent A composite control which will be the parent of the new instance (cannot be null). * @param name The unique component name. * @param style The style of control to construct. * @see #STYLE_WRAP * @see #STYLE_READ_ONLY */ public Spinner(Container parent, String name, int style) { super(parent, name, style); sendMessage(MESSAGE_INITIALIZE, new int[] {parent.getNumber(), style}); }//Spinner()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#getClientClassName() */ protected String getClientClassName() { return "com.foundation.tcv.swt.client.Spinner"; }//getClientClassName()// /** * Sets the component maximum selection value. * @param maximum The maximum value in the selection range. */ public void setMaximum(Integer maximum) { verifyThread(); this.maximum.setDefaultValue(maximum); }//setMaximum()// /** * Sets the component minimum selection value. * @param minimum The minimum value in the selection range. This must be greater than or equal to zero. */ public void setMinimum(Integer minimum) { verifyThread(); this.minimum.setDefaultValue(minimum); }//setMinimum()// /** * Sets the slider increment. * @param increment The increment value for the range. */ public void setIncrement(Integer increment) { verifyThread(); this.increment.setDefaultValue(increment); }//setIncrement()// /** * Sets the slider page increment. * @param pageIncrement The page increment value for the range. */ public void setPageIncrement(Integer pageIncrement) { verifyThread(); this.pageIncrement.setDefaultValue(pageIncrement); }//setIncrement()// /** * Sets the association container used to access the maximum value. * @param container The maximum value association metadata. */ public void setMaximumAssociation(SingleAssociationContainer container) { verifyThread(); this.maximum.setAssociations(container); }//setMaximumAssociation()// /** * Sets the association container used to access the minimum value. * @param container The minimum value association metadata. */ public void setMinimumAssociation(SingleAssociationContainer container) { verifyThread(); this.minimum.setAssociations(container); }//setMinimumAssociation()// /** * Sets the association container used to access the selected value. * @param container The selected value association metadata. */ public void setSelectionAssociation(SingleAssociationContainer container) { verifyThread(); this.selection.setAssociations(container); }//setSelectionAssociation()// /** * Sets the association container used to access the increment size. * @param container The increment size association metadata. */ public void setIncrementAssociation(SingleAssociationContainer container) { verifyThread(); this.increment.setAssociations(container); }//setIncrementAssociation()// /** * Sets the association container used to access the page increment size. * @param container The page increment size association metadata. */ public void setPageIncrementAssociation(SingleAssociationContainer container) { verifyThread(); this.pageIncrement.setAssociations(container); }//setPageIncrementAssociation()// /** * Gets whether the selection will automatically synchronize. * @return Whether the selection is automatically synchronized from the view to the model when changed, or whether it must be manually synchronized. */ protected boolean getAutoSynchronizeSelection() { return autoSynchronizeSelection; }//getAutoSynchronizeSelection()// /** * Sets whether the selection will automatically synchronize. * @param autoSynchronizeSelection Whether the selection is automatically synchronized from the view to the model when changed, or whether it must be manually synchronized. */ public void setAutoSynchronizeSelection(boolean autoSynchronizeSelection) { verifyThread(); if(this.autoSynchronizeSelection != autoSynchronizeSelection) { this.autoSynchronizeSelection = autoSynchronizeSelection; sendMessage(MESSAGE_SET_AUTO_SYNCHRONIZE_SELECTION, autoSynchronizeSelection ? Boolean.TRUE : Boolean.FALSE); }//if// }//setAutoSynchronizeSelection()// /** * Gets the number of milliseconds to wait before automatically synchronizing selection changes. This must be a number between zero and ten thousand where zero synchronizes without delay. * @return The number of milliseconds of delay when auto synchronizing the selection. */ protected long getAutoSynchronizeSelectionDelay() { return autoSynchronizeSelectionDelay; }//getAutoSynchronizeSelectionDelay()// /** * Sets the number of milliseconds to wait before automatically synchronizing selection changes. This must be a number between zero and ten thousand where zero synchronizes without delay. * @param autoSynchronizeSelectionDelay The number of milliseconds of delay when auto synchronizing the selection. */ public void setAutoSynchronizeSelectionDelay(long autoSynchronizeSelectionDelay) { verifyThread(); if(autoSynchronizeSelectionDelay < 0) { autoSynchronizeSelectionDelay = 0; }//if// else if(autoSynchronizeSelectionDelay > 10000) { autoSynchronizeSelectionDelay = 10000; }//else if// if(this.autoSynchronizeSelectionDelay != autoSynchronizeSelectionDelay) { this.autoSynchronizeSelectionDelay = autoSynchronizeSelectionDelay; sendMessage(MESSAGE_SET_AUTO_SYNCHRONIZE_SELECTION_DELAY, new Long(autoSynchronizeSelectionDelay)); }//if// }//setAutoSynchronizeSelectionDelay()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewInitialize() */ protected void internalViewInitialize() { super.internalViewInitialize(); maximum.initialize(); minimum.initialize(); selection.initialize(); increment.initialize(); pageIncrement.initialize(); }//internalViewInitialize()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRelease() */ protected void internalViewRelease() { super.internalViewRelease(); maximum.release(); minimum.release(); selection.release(); increment.release(); pageIncrement.release(); }//internalViewRelease()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRefresh() */ protected void internalViewRefresh() { super.internalViewRefresh(); internalViewRefreshMaximum(); internalViewRefreshMinimum(); internalViewRefreshSelection(); internalViewRefreshIncrement(); internalViewRefreshPageIncrement(); }//internalViewRefresh()// /** * Refreshes the selection maximum. */ protected void internalViewRefreshMaximum() { if(maximum.refresh()) { sendMessage(MESSAGE_SET_MAXIMUM, (Integer) maximum.getValue()); }//if// }//internalViewRefreshMaximum()// /** * Refreshes the selection maximum. */ protected void internalViewRefreshMinimum() { if(minimum.refresh()) { sendMessage(MESSAGE_SET_MINIMUM, (Integer) minimum.getValue()); }//if// }//internalViewRefreshMinimum()// /** * Refreshes the current selection. */ protected void internalViewRefreshSelection() { if(selection.refresh()) { sendMessage(MESSAGE_SET_SELECTION, (Integer) selection.getValue()); }//if// }//internalViewRefreshSelection()// /** * Refreshes the increment. */ protected void internalViewRefreshIncrement() { if(selection.refresh()) { sendMessage(MESSAGE_SET_INCREMENT, (Integer) increment.getValue()); }//if// }//internalViewRefreshIncrement()// /** * Refreshes the page increment. */ protected void internalViewRefreshPageIncrement() { if(selection.refresh()) { sendMessage(MESSAGE_SET_PAGE_INCREMENT, (Integer) pageIncrement.getValue()); }//if// }//internalViewRefreshPageIncrement()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalOnValueChanged(com.foundation.view.SingleResourceAssociation) */ protected void internalOnValueChanged(SingleResourceAssociation resourceAssociation, int flags) { if(resourceAssociation == maximum) { internalViewRefreshMaximum(); }//if// else if(resourceAssociation == minimum) { internalViewRefreshMinimum(); }//else if// else if(resourceAssociation == selection) { internalViewRefreshSelection(); }//else if// else if(resourceAssociation == increment) { internalViewRefreshIncrement(); }//else if// else if(resourceAssociation == pageIncrement) { internalViewRefreshPageIncrement(); }//else if// else { super.internalOnValueChanged(resourceAssociation, flags); }//else// }//internalOnValueChanged()// /* (non-Javadoc) * @see com.foundation.tcv.view.IViewComponent#processMessage(com.foundation.tcv.model.ViewMessage) */ public Object processMessage(ViewMessage viewMessage) { Object retVal = null; switch(viewMessage.getMessageNumber()) { case MESSAGE_VIEW_SYNCHRONIZE_SELECTION: { Object selection = (Object) viewMessage.getMessageData(); this.selection.setValue(selection); break; }//case// default: { retVal = super.processMessage(viewMessage); }//default// }//switch// return retVal; }//processMessage()// }//Spinner()//