Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright (c) 2003, 2010 s IT Solutions AT Spardat GmbH .
* 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:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
// @(#) $Id: $
package at.spardat.xma.mdl.paging;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
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.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import at.spardat.xma.page.Scaler;
/**
* Implements the user interface for the paging model. Plays the role of the SWT-control.
* The appearance of the user interface can be customized using the parameter sytle
* of the constructor.
*
* @author gub
* @since 2.3.0
*/
public class PagingControlClient extends Composite implements SelectionListener, ModifyListener {
/** show the start button */
public static final short SHOW_START=1;
/** show the fast back button */
public static final short SHOW_FASTBACK=2;
/** show the back button */
public static final short SHOW_BACK=4;
/** show the reload button */
public static final short SHOW_RELOAD=8;
/** show the jump combo */
public static final short SHOW_JUMP=16;
/** show the next button */
public static final short SHOW_NEXT=32;
/** show the fast next button */
public static final short SHOW_FASTNEXT=64;
/** show the end button */
public static final short SHOW_END=128;
/** show the info label */
public static final short SHOW_INFO=256;
/** show the pageSize combo */
public static final short SHOW_PAGESIZE=512;
/** show the customize button */
public static final short SHOW_CUSTOMIZE=1024;
/** show the export button */
public static final short SHOW_EXPORT=2048;
/** show start, back, jump, next, end */
public static final short JUMPNAV=SHOW_START|SHOW_BACK|SHOW_JUMP|SHOW_NEXT|SHOW_END;
/** show fast back, back, reload, next, fast next */
public static final short SCROLLNAV=SHOW_FASTBACK|SHOW_BACK|SHOW_RELOAD|SHOW_NEXT|SHOW_FASTNEXT;
/** show all of {@link #JUMPNAV} and info label and pageSize combo */
public static final short DEFAULT=JUMPNAV|SHOW_INFO|SHOW_PAGESIZE;
/** resource bundle containing all localized strings of PagingControlClient */
public static final String resourceBundle = "at.spardat.xma.mdl.paging.PagingHeader";
protected Control startW;
protected Control fastBackW;
protected Control backW;
protected Control reloadW;
protected Combo jumpW;
protected Control nextW;
protected Control fastNextW;
protected Control endW;
protected Label info;
protected Control customizeW;
protected Control exportW;
protected Combo pageSizeW;
protected Label pageSizeL;
protected Locale locale;
/** holds the visibility flags ored together */
protected int style;
List selectionListeners = new ArrayList(1);
List modifyListeners = new ArrayList(1);
/**
* Constructs the PagingControlClient.
* @param parent the widget which will be the parent of the new instance (cannot be null)
* @param locale the locale to use the desired language
* @param style some style flags of this class ored together
* @param swtStyle the style flags to pass to the base SWT-Composite.
*/
public PagingControlClient(Composite parent,Locale locale, int style,int swtStyle) {
super(parent, swtStyle);
this.locale=locale;
this.style=style;
createWidgets();
}
/**
* Creates and initializes all the widgets this control is composed by.
* Calculates the layout corresponding to the style flags.
* Defines the tab order.
*/
protected void createWidgets() {
FormData data;
Control[] tabOrder;
ResourceBundle messages = ResourceBundle.getBundle(resourceBundle,locale);
final Scaler scaler = Scaler.getInstance(this);
FormLayout layout = new FormLayout();
layout.marginHeight = scaler.convertYToCurrent(3);
layout.marginWidth = scaler.convertXToCurrent(3);
this.setLayout(layout);
startW = new Button (this, SWT.PUSH|SWT.CENTER);
((Button)startW).setText(messages.getString("startW"));
startW.setToolTipText(messages.getString("startWTip"));
((Button)startW).addSelectionListener(this);
fastBackW = new Button (this, SWT.PUSH|SWT.CENTER);
((Button)fastBackW).setText(messages.getString("fastBackW"));
((Button)fastBackW).addSelectionListener(this);
backW = new Button (this, SWT.PUSH|SWT.CENTER);
((Button)backW).setText(messages.getString("backW"));
backW.setToolTipText(messages.getString("backWTip"));
((Button)backW).addSelectionListener(this);
reloadW = new Button (this, SWT.PUSH|SWT.CENTER);
((Button)reloadW).setText(messages.getString("reloadW"));
reloadW.setToolTipText(messages.getString("reloadWTip"));
((Button)reloadW).addSelectionListener(this);
jumpW = new Combo(this, SWT.DROP_DOWN|SWT.BORDER);
jumpW.setToolTipText(messages.getString("jumpWTip"));
jumpW.addModifyListener(this);
jumpW.addSelectionListener(this);
nextW = new Button (this, SWT.PUSH|SWT.CENTER);
((Button)nextW).setText(messages.getString("nextW"));
nextW.setToolTipText(messages.getString("nextWTip"));
((Button)nextW).addSelectionListener(this);
fastNextW = new Button (this, SWT.PUSH|SWT.CENTER);
((Button)fastNextW).setText(messages.getString("fastNextW"));
((Button)fastNextW).addSelectionListener(this);
endW = new Button (this, SWT.PUSH|SWT.CENTER);
((Button)endW).setText(messages.getString("endW"));
endW.setToolTipText(messages.getString("endWTip"));
((Button)endW).addSelectionListener(this);
customizeW = new Button (this, SWT.PUSH|SWT.CENTER);
((Button)customizeW).setText(messages.getString("customizeW"));
customizeW.setToolTipText(messages.getString("customizeWTip"));
((Button)customizeW).addSelectionListener(this);
exportW = new Button (this, SWT.PUSH|SWT.CENTER);
((Button)exportW).setText(messages.getString("exportW"));
exportW.setToolTipText(messages.getString("exportWTip"));
((Button)exportW).addSelectionListener(this);
info = new Label (this,SWT.LEFT);
pageSizeL = new Label (this,SWT.LEFT);
pageSizeL.setText(messages.getString("pageSizeL"));
pageSizeW = new Combo(this, SWT.DROP_DOWN|SWT.BORDER);
pageSizeW.setToolTipText(messages.getString("pageSizeWTip"));
pageSizeW.addModifyListener(this);
pageSizeW.addSelectionListener(this);
Control lastControl=null;
if((SHOW_START&style)!=0) {
data = new FormData();
data.width = scaler.convertXToCurrent(30);
data.left = new FormAttachment(0,100,scaler.convertXToCurrent(0));
data.bottom = new FormAttachment(100,100,scaler.convertYToCurrent(0));
startW.setLayoutData(data);
lastControl=startW;
} else {
startW.setVisible(false);
}
if((SHOW_FASTBACK&style)!=0) {
data = new FormData();
data.width = scaler.convertXToCurrent(30);
if(lastControl==null) {
data.left = new FormAttachment(0,100,scaler.convertXToCurrent(0));
} else {
data.left = new FormAttachment(lastControl,scaler.convertXToCurrent(3),SWT.RIGHT);
}
data.bottom = new FormAttachment(100,100,scaler.convertYToCurrent(0));
fastBackW.setLayoutData(data);
lastControl=fastBackW;
} else {
fastBackW.setVisible(false);
}
if((SHOW_BACK&style)!=0) {
data = new FormData();
data.width = scaler.convertXToCurrent(30);
if(lastControl==null) {
data.left = new FormAttachment(0,100,scaler.convertXToCurrent(0));
} else {
data.left = new FormAttachment(lastControl,scaler.convertXToCurrent(3),SWT.RIGHT);
}
data.bottom = new FormAttachment(100,100,scaler.convertYToCurrent(0));
backW.setLayoutData(data);
lastControl=backW;
} else {
backW.setVisible(false);
}
if((SHOW_RELOAD&style)!=0) {
data = new FormData();
data.width = scaler.convertXToCurrent(30);
if(lastControl==null) {
data.left = new FormAttachment(0,100,scaler.convertXToCurrent(0));
} else {
data.left = new FormAttachment(lastControl,scaler.convertXToCurrent(3),SWT.RIGHT);
}
data.bottom = new FormAttachment(100,100,scaler.convertYToCurrent(0));
reloadW.setLayoutData(data);
lastControl=reloadW;
} else {
reloadW.setVisible(false);
}
if((SHOW_JUMP&style)!=0) {
data = new FormData();
data.width = scaler.convertXToCurrent(15);
if(lastControl==null) {
data.left = new FormAttachment(0,100,scaler.convertXToCurrent(0));
data.bottom = new FormAttachment(100,100,scaler.convertYToCurrent(0));
} else {
data.left = new FormAttachment(lastControl,scaler.convertXToCurrent(3),SWT.RIGHT);
data.top = new FormAttachment(lastControl,scaler.convertYToCurrent(0),SWT.CENTER);
}
jumpW.setLayoutData(data);
lastControl=jumpW;
} else {
jumpW.setVisible(false);
}
if((SHOW_NEXT&style)!=0) {
data = new FormData();
data.width = scaler.convertXToCurrent(30);
if(lastControl==null) {
data.left = new FormAttachment(0,100,scaler.convertXToCurrent(0));
} else {
data.left = new FormAttachment(lastControl,scaler.convertXToCurrent(3),SWT.RIGHT);
}
data.bottom = new FormAttachment(100,100,scaler.convertYToCurrent(0));
nextW.setLayoutData(data);
lastControl=nextW;
} else {
nextW.setVisible(false);
}
if((SHOW_FASTNEXT&style)!=0) {
data = new FormData();
data.width = scaler.convertXToCurrent(30);
if(lastControl==null) {
data.left = new FormAttachment(0,100,scaler.convertXToCurrent(0));
} else {
data.left = new FormAttachment(lastControl,scaler.convertXToCurrent(3),SWT.RIGHT);
}
data.bottom = new FormAttachment(100,100,scaler.convertYToCurrent(0));
fastNextW.setLayoutData(data);
lastControl=fastNextW;
} else {
fastNextW.setVisible(false);
}
if((SHOW_END&style)!=0) {
data = new FormData();
data.width = scaler.convertXToCurrent(30);
if(lastControl==null) {
data.left = new FormAttachment(0,100,scaler.convertXToCurrent(0));
} else {
data.left = new FormAttachment(lastControl,scaler.convertXToCurrent(3),SWT.RIGHT);
}
data.bottom = new FormAttachment(100,100,scaler.convertYToCurrent(0));
endW.setLayoutData(data);
lastControl=endW;
} else {
endW.setVisible(false);
}
if((SHOW_INFO&style)!=0) {
data = new FormData();
if(lastControl==null) {
data.left = new FormAttachment(0,100,scaler.convertXToCurrent(0));
} else {
data.left = new FormAttachment(lastControl,scaler.convertXToCurrent(3),SWT.RIGHT);
}
data.right = new FormAttachment(pageSizeL,scaler.convertXToCurrent(-3),SWT.LEFT);
data.top = new FormAttachment(endW,scaler.convertYToCurrent(0),SWT.CENTER);
info.setLayoutData(data);
} else {
info.setVisible(false);
}
lastControl=null;
if((SHOW_PAGESIZE&style)!=0) {
data = new FormData();
data.width = scaler.convertXToCurrent(25);
data.right = new FormAttachment(100,100,scaler.convertXToCurrent(0));
data.bottom = new FormAttachment(100,100,scaler.convertYToCurrent(0));
pageSizeW.setLayoutData(data);
data = new FormData();
data.right = new FormAttachment(pageSizeW,scaler.convertXToCurrent(-3),SWT.LEFT);
data.top = new FormAttachment(info,scaler.convertYToCurrent(0),SWT.CENTER);
pageSizeL.setLayoutData(data);
lastControl=pageSizeL;
} else {
pageSizeW.setVisible(false);
pageSizeL.setVisible(false);
}
if((SHOW_CUSTOMIZE&style)!=0) {
data = new FormData();
data.width = scaler.convertXToCurrent(30);
if(lastControl==null) {
data.right = new FormAttachment(100,100,scaler.convertXToCurrent(0));
} else {
data.right = new FormAttachment(lastControl,scaler.convertXToCurrent(-3),SWT.LEFT);
}
data.bottom = new FormAttachment(100,100,scaler.convertYToCurrent(0));
customizeW.setLayoutData(data);
lastControl=customizeW;
} else {
customizeW.setVisible(false);
}
if ((SHOW_EXPORT&style)!=0) {
data = new FormData();
data.width = scaler.convertXToCurrent(30);
if(lastControl==null) {
data.right = new FormAttachment(100,100,scaler.convertXToCurrent(0));
} else {
data.right = new FormAttachment(lastControl,scaler.convertXToCurrent(-3),SWT.LEFT);
}
data.bottom = new FormAttachment(100,100,scaler.convertYToCurrent(0));
exportW.setLayoutData(data);
lastControl=exportW;
} else {
exportW.setVisible(false);
}
tabOrder = new Control[10];
tabOrder[0] = startW;
tabOrder[1] = fastBackW;
tabOrder[2] = backW;
tabOrder[3] = reloadW;
tabOrder[4] = jumpW;
tabOrder[5] = nextW;
tabOrder[6] = fastNextW;
tabOrder[7] = endW;
tabOrder[8] = customizeW;
tabOrder[9] = pageSizeW;
setTabList(tabOrder);
}
/**
* This event is not defined for buttons or combos.
* Otherwise it would be called by SWT if any button or combo of this control is default selected.
*/
public void widgetDefaultSelected(SelectionEvent e) {
for(Iterator it=selectionListeners.iterator();it.hasNext();) {
((SelectionListener)it.next()).widgetDefaultSelected(e);
}
}
/**
* Called by SWT if any button of this control is selected,
* or a new value was selected for one of the combos.
*/
public void widgetSelected(SelectionEvent e) {
for(Iterator it=selectionListeners.iterator();it.hasNext();) {
((SelectionListener)it.next()).widgetSelected(e);
}
}
/**
* Called by SWT if the text of one of the combos was changed by the user.
*/
public void modifyText(ModifyEvent e) {
for(Iterator it=modifyListeners.iterator();it.hasNext();) {
((ModifyListener)it.next()).modifyText(e);
}
}
/**
* Add a listener that has to be notified if any button of this control is selected,
* or a new value was selected for one of the combos.
*/
public void addSelecionListener(SelectionListener listener) {
if(!selectionListeners.contains(listener)) selectionListeners.add(listener);
}
/**
* Add a listener that has to be notified if the text of one of the combos was changed by the user.
*/
public void addModifyListener(ModifyListener listener) {
if(!modifyListeners.contains(listener)) modifyListeners.add(listener);
}
/**
* Sets the icon of the start button.
*/
public void setStartIcon(Image icon) {
((Button)startW).setImage(icon);
}
/**
* Sets the icon of the fast back button.
*/
public void setFastBackIcon(Image icon) {
((Button)fastBackW).setImage(icon);
}
/**
* Sets the icon of the back button.
*/
public void setBackIcon(Image icon) {
((Button)backW).setImage(icon);
}
/**
* Sets the icon of the reload button.
*/
public void setReloadIcon(Image icon) {
((Button)reloadW).setImage(icon);
}
/**
* Sets the icon of the next button.
*/
public void setNextIcon(Image icon) {
((Button)nextW).setImage(icon);
}
/**
* Sets the icon of the fast next button.
*/
public void setFastNextIcon(Image icon) {
((Button)fastNextW).setImage(icon);
}
/**
* Sets the icon of the end button.
*/
public void setEndIcon(Image icon) {
((Button)endW).setImage(icon);
}
/**
* Sets the icon of the customize button.
*/
public void setCusomizeIcon(Image icon) {
((Button)customizeW).setImage(icon);
}
/**
* Sets the icon for the export icon
*/
public void setExportIcon(Image icon) {
((Button)exportW).setImage(icon);
}
/**
* Sets the background for this PagingControl.
* the background color is also set for the labels
*/
public void setBackground(Color color) {
super.setBackground(color);
info.setBackground(color);
pageSizeL.setBackground(color);
}
}