home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
jbuilder
/
jsamples.z
/
ResourceableLineItemDetailEditor.java
< prev
next >
Wrap
Text File
|
1997-07-24
|
6KB
|
198 lines
package borland.samples.intl.application;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import borland.jbcl.util.*;
import borland.jbcl.view.*;
import borland.jbcl.control.*;
import borland.jbcl.model.*;
/**
* Custom model-view item editor for editing product detail info (size
* or color) of rows in orderLineItemDataSet. When a user begins
* editing the Size/Color column of orderLineItemDataSet,
* ResourceableLineItemDetailEditor's startEdit() method is invoked
* automatically. ResourceableLineItemDetailEditor then calls
* AppDataModule.getLookupChoices() to get a list of non-localized
* possible colors and sizes for the current line item row (sku).
* ResourceableLineItemDetailEditor looks up the non-localized strings
* in its resource bundle, then presents the localized choices within
* one, or if necessary, two ChoiceControls. When the user selects a
* value from the ChoiceControl, the getValue() method is called
* automatically, and ResourceableLineItemDetailEditor returns the
* corresponding non-localized string input into the column.
*/
public class ResourceableLineItemDetailEditor extends Panel implements ItemEditor {
AppDataModule appDataModule;
ResourceBundle resourceBundle;
ChoiceControl colorChoice = new ChoiceControl();
ChoiceControl sizeChoice = new ChoiceControl();
ChoiceControl noChoice = new ChoiceControl();
String [] colors;
String [] sizes;
public ResourceableLineItemDetailEditor(AppDataModule appDataModule) {
super();
this.appDataModule = appDataModule;
setLayout(new FlowLayout());
}
public ResourceableLineItemDetailEditor() {
this(null);
}
public void setAppDataModule(AppDataModule appDataModule) {
this.appDataModule = appDataModule;
}
public AppDataModule getAppDataModule() {
return appDataModule;
}
public void setResourceBundle(ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
}
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
public void addKeyListener(KeyListener l) {
colorChoice.addKeyListener(l);
sizeChoice.addKeyListener(l);
noChoice.addKeyListener(l);
}
public void removeKeyListener(KeyListener l) {
colorChoice.removeKeyListener(l);
sizeChoice.removeKeyListener(l);
noChoice.addKeyListener(l);
}
public Object getValue() {
Variant variant = new Variant();
String value = "";
if (colors.length > 0) {
value += colors[colorChoice.getSelectedIndex()];
}
if (sizes.length > 0) {
if (value.length() != 0) {
value += ",";
}
value += sizes[sizeChoice.getSelectedIndex()];
}
if (value.length() == 0) {
value = "N/A";
}
variant.setString(value);
return variant;
}
public Component getComponent() {
return this;
}
public void startEdit(Object value, Rectangle bounds, ItemEditSite site) {
boolean noChoices = true;
Component focusedComponent = null;
// remove all Choice objects contained by this panel
removeAll();
StringTokenizer tokenizer = new StringTokenizer(value.toString(), ",", false);
if (appDataModule == null) {
colors = new String[0];
} else {
colors = appDataModule.getLookupChoices(appDataModule.getOrderLineItemDataSet(), "sku", appDataModule.getProductColorsDataSet(), "available_colors");
}
if (colors.length > 0) {
String currentColor = colors[0];
if (tokenizer.hasMoreTokens()) {
currentColor = tokenizer.nextToken();
}
colorChoice.removeAll();
int currentColorIndex = 0;
for (int i = 0; i < colors.length; i++) {
if (colors[i].equals(currentColor)) {
currentColorIndex = i;
}
if (resourceBundle == null) {
colorChoice.addItem(colors[i]);
} else {
colorChoice.addItem(resourceBundle.getString(colors[i]));
}
}
colorChoice.select(currentColorIndex);
focusedComponent = colorChoice;
add(colorChoice);
colorChoice.invalidate();
}
if (appDataModule == null) {
sizes = new String[0];
} else {
sizes = appDataModule.getLookupChoices(appDataModule.getOrderLineItemDataSet(), "sku", appDataModule.getProductSizesDataSet(), "available_sizes");
}
if (sizes.length > 0) {
String currentSize = sizes[0];
if (tokenizer.hasMoreTokens()) {
currentSize = tokenizer.nextToken();
}
sizeChoice.removeAll();
int currentSizeIndex = 0;
for (int i = 0; i < sizes.length; i++) {
if (sizes[i].equals(currentSize)) {
currentSizeIndex = i;
}
if (resourceBundle == null) {
sizeChoice.add(sizes[i]);
} else {
sizeChoice.add(resourceBundle.getString(sizes[i]));
}
}
sizeChoice.select(currentSizeIndex);
focusedComponent = sizeChoice;
add(sizeChoice);
sizeChoice.invalidate();
}
if (colors.length == 0 && sizes.length == 0) {
noChoice.add(resourceBundle.getString("N/A"));
add(noChoice);
focusedComponent = noChoice;
}
setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
if (site != null) {
setBackground(site.getBackground());
setForeground(site.getForeground());
setFont(site.getFont());
}
validate();
setVisible(true);
focusedComponent.requestFocus();
}
public void changeBounds(Rectangle bounds) {
setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
sizeChoice.invalidate();
colorChoice.invalidate();
noChoice.invalidate();
validate();
}
public boolean canPost() {
return true;
}
public void endEdit(boolean posted) {
setBounds(0,0,0,0);
setVisible(false);
}
}