You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2001/05/08 08:29:10 UTC
cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/modules/screens Customizer1.java Customizer2.java
taylor 01/05/07 23:29:10
Added: src/java/org/apache/jetspeed/modules/screens
Customizer1.java Customizer2.java
Log:
adding Glucode customizer for 1.3a2
Revision Changes Path
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/screens/Customizer1.java
Index: Customizer1.java
===================================================================
package org.apache.jetspeed.modules.screens;
/*
*
* Copyright (c) 1998 The Java Apache Project. All rights reserved.
*
* 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. Every modification must be notified to the Java Apache Project
* and redistribution of the modified code without prior notification
* is not permitted in any form.
*
* 4. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Java Apache Project
* (http://java.apache.org/)."
*
* 5. The names "Jetspeed", "Apache Jetspeed" and "Apache Jetspeed
* Project" must not be used to endorse or promote products
* derived from this software without prior written permission.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Java Apache Project
* (http://java.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "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 JAVA APACHE 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.
*
* License version 1.0
*
*/
//ECS
import org.apache.ecs.html.*;
import org.apache.ecs.*;
//turbine
import org.apache.turbine.modules.*;
import org.apache.turbine.util.*;
import org.apache.turbine.services.resources.TurbineResources;
// Customizer
import org.apache.jetspeed.util.customization.*;
import java.util.Comparator;
import java.util.Vector;
import java.util.Collections;
/**
* First screen to customization.
*
* @author <a href="mailto:vtruong@gluecode.com">Van Truong </a>
* @author <a href="mailto:eros@gluecode.com">Ernest Ros </a>
* @version $Id: Customizer1.java,v 1.1 2001/05/08 06:29:08 taylor Exp $
*
*/
public class Customizer1 extends Screen
{
public ConcreteElement doBuild(RunData data) throws Exception
{
// Check to make sure the user has logged in before accessing this screen
if (!data.getUser().hasLoggedIn())
{
data.setMessage("USER HAS NOT LOGGED IN.");
return ScreenLoader.getInstance().eval ( data, TurbineResources.getString( "screen.mainmenu" ) );
}
// Get the parameters
AllowablePortletSet portletSet = (AllowablePortletSet)data.getUser().getTemp(CustomizerResources.ALLOWABLEPORTLETSET);
if (portletSet==null)
{
// This occurs when user tried to access this screen out of sequence
data.setMessage("WARNING: USER HAS NOT START THE CUSTOMIZATION PROCESS FROM THE BEGINNING.");
return ScreenLoader.getInstance().eval ( data, TurbineResources.getString( "screen.mainmenu" ) );
}
//Set parameter to be passed
data.setTitle("GlueCode Customizer Page 1");
data.getUser().setTemp(CustomizerResources.PREVIOUSSCREEN, CustomizerResources.CUSTOMIZERSCREEN1);
// Define the form
DynamicURI uri = new DynamicURI(data);
uri.setScreen(CustomizerResources.CUSTOMIZERSCREEN1);
uri.setAction(CustomizerResources.CUSTOMIZERACTION1);
Form form = new Form(uri.toString()).setMethod(Form.POST);
Input cancelBut = new Input(Input.SUBMIT, "eventSubmit_doCancel", "Cancel");
Input resetBut = new Input(Input.RESET, "", "Reset");
Input continueBut = new Input(Input.SUBMIT, "eventSubmit_doContinue", "Continue");
// Define the main outer table
TD[] mainTD = {new TD().setWidth("100%"), new TD().setWidth("100%")};
TR[] mainTR = {new TR().addElement(mainTD[0]),
new TR().addElement(mainTD[1]),
new TR().addElement(new TD().addElement(resetBut)
.addElement(cancelBut)
.addElement(continueBut)
.setAlign("right"))};
Table mainTable = new Table().setCellSpacing(0)
.setCellPadding(1)
.setBorder(0)
.setWidth("100%")
.addElement(mainTR[0])
.addElement(mainTR[1])
.addElement(mainTR[2]);
// Define the portlets selection table
Table portletTable = new Table().setCellSpacing(0)
.setCellPadding(1)
.setBorder(0)
.setWidth("100%");
// Define the portlet selection headings
TR pHeadingTR[] = new TR[4];
pHeadingTR[0] = new TR().addElement(new TD(new B().addElement("PORTLET SELECTION"))
.setColSpan(4)
.setAlign("center"));
pHeadingTR[1] = new TR().addElement(new TD(new B("Portlet")).setWidth("25%").setAlign("center"))
.addElement(new TD(new B("Description")).setWidth("25%").setAlign("center"))
.addElement(new TD(new B("Portlet")).setWidth("25%").setAlign("center"))
.addElement(new TD(new B("Description")).setWidth("25%").setAlign("center"))
.setBgColor(HtmlColor.LIGHTBLUE);
pHeadingTR[2] = new TR().addElement(new TD(new HR()).setColSpan(4));
pHeadingTR[3] = new TR().addElement(new TD(new HR()).setColSpan(4));
portletTable.addElement(pHeadingTR[0])
.addElement(pHeadingTR[2])
.addElement(pHeadingTR[1])
.addElement(pHeadingTR[3]);
// Define the columns and rows
String[] portletNames = this.getSortedPortletNames(portletSet);
int numOfCol = 2;
int remainder = portletNames.length%numOfCol;
int numOfRow = (int)(portletNames.length/numOfCol) + (remainder>0?1:0);
TR[] portletTR = new TR[numOfRow];
// Begin adding the data to the portlet section table
// Create the rows in the first for loop
for (int i=0; i<numOfRow; i++)
{
Input input = new Input().setName(CustomizerResources.CHECKBOXPREFIX +
CustomizerResources.PORTLET)
.setValue(portletNames[i])
.addElement(portletSet.getPortletTitle(portletNames[i]))
.setType(Input.CHECKBOX)
.setChecked(portletSet.isUserDefaultPortlet(portletNames[i]))
.setDisabled(portletSet.isMandatoryPortlet(portletNames[i]));
TD tdPortletName = new TD().addElement(input)
.setWidth("25%")
.setVAlign("top");
TD tdPortletDesc = new TD().addElement(portletSet.getPortletDescription(portletNames[i]))
.setWidth("25%")
.setVAlign("top");
portletTR[i] = new TR().addElement(tdPortletName)
.addElement(tdPortletDesc);
portletTable.addElement(portletTR[i]);
} //end for
// Add to the row (now that the are created) in the second for loop
for (int i=numOfRow; i<portletNames.length; i++)
{
Input input = new Input().setName(CustomizerResources.CHECKBOXPREFIX +
CustomizerResources.PORTLET)
.setValue(portletNames[i])
.addElement(portletSet.getPortletTitle(portletNames[i]))
.setType(Input.CHECKBOX)
.setChecked(portletSet.isUserDefaultPortlet(portletNames[i]))
.setDisabled(portletSet.isMandatoryPortlet(portletNames[i]));
TD tdPortletName = new TD().addElement(input)
.setWidth("25%")
.setVAlign("top");
TD tdPortletDesc = new TD().addElement(portletSet.getPortletDescription(portletNames[i]))
.setWidth("25%")
.setVAlign("top");
portletTR[i%numOfRow].addElement(tdPortletName)
.addElement(tdPortletDesc);
} //end for
// Add the unused table data to even out the table
for (int i=portletNames.length; i<(numOfRow*numOfCol); i++)
{
portletTR[i%numOfRow].addElement(new TD().setWidth("25%"))
.addElement(new TD().setWidth("25%"));
} //end for
// Define the headings
TR lHeadingTR[] = new TR[2];
lHeadingTR[0] = new TR().addElement(new TD(new B("LAYOUT SELECTION")).setColSpan(4)
.setAlign("center"))
.setBgColor(HtmlColor.LIGHTBLUE);
lHeadingTR[1] = new TR().addElement(new TD(new B(" ")).setWidth("25%"))
.addElement(new TD(new B("Left Column")).setWidth("25%"))
.addElement(new TD(new B("Middle Column")).setWidth("25%"))
.addElement(new TD(new B("Right Column")).setWidth("25%"));
mainTD[0].addElement(portletTable);
//mainTD[1].addElement(layoutTable);
form.addElement(mainTable);
ElementContainer ec = new ElementContainer(form);
return ec;
}
private String[] getSortedPortletNames(AllowablePortletSet ap)
{
String[] portletNames = ap.getAllowablePortletNames();
Vector sortedPortlets = new Vector(portletNames.length);
for (int i=0; i<portletNames.length; i++) {
sortedPortlets.add(portletNames[i]);
}// end for
PortletComparator pc = new PortletComparator(ap);
Collections.sort(sortedPortlets, pc);
for (int i=0; i<portletNames.length; i++)
{
portletNames[i] = (String) sortedPortlets.get(i);
} // end for
return portletNames;
}// end sortPortlets()
private class PortletComparator implements Comparator
{
private AllowablePortletSet ap;
public PortletComparator(AllowablePortletSet theAp)
{
this.ap = theAp;
}// end constructor()
public int compare (Object o1, Object o2)
{
String str1 = null;
String str2 = null;
try
{
str1 = ap.getPortletTitle((String) o1);
str2 = ap.getPortletTitle((String) o2);
}
catch (ElementNotFoundException e)
{
// do nothing
}
return str1.compareToIgnoreCase(str2);
}// end compare()
public boolean equals(Object o1, Object o2)
{
if (this.compare(o1, o2) == 0)
return true;
return false;
}// end equals()
}// end class PortletComparator
} //GlueCodeCustomer1
1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/modules/screens/Customizer2.java
Index: Customizer2.java
===================================================================
package org.apache.jetspeed.modules.screens;
/*
*
* Copyright (c) 1998 The Java Apache Project. All rights reserved.
*
* 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. Every modification must be notified to the Java Apache Project
* and redistribution of the modified code without prior notification
* is not permitted in any form.
*
* 4. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Java Apache Project
* (http://java.apache.org/)."
*
* 5. The names "Jetspeed", "Apache Jetspeed" and "Apache Jetspeed
* Project" must not be used to endorse or promote products
* derived from this software without prior written permission.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Java Apache Project
* (http://java.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "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 JAVA APACHE 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.
*
* License version 1.0
*
*/
//ECS
import org.apache.ecs.html.*;
import org.apache.ecs.*;
//turbine
import org.apache.turbine.modules.*;
import org.apache.turbine.util.*;
import org.apache.turbine.services.resources.TurbineResources;
//GlueCode
import org.apache.jetspeed.util.customization.*;
import java.util.LinkedList;
import java.util.Comparator;
import java.util.Collection;
import java.util.Collections;
/**
*Second to customization.
*/
public class Customizer2 extends Screen
{
private static final String SPACERNAME = "spacer";
private static final String FORMNAME = "customizer";
public ConcreteElement doBuild(RunData rdata) throws Exception
{
// Check to make sure the user has logged in before accessing this screen
if (!rdata.getUser().hasLoggedIn())
{
rdata.setMessage("USER HAS NOT LOGGED IN.");
return ScreenLoader.getInstance().eval ( rdata, TurbineResources.getString( "screen.mainmenu" ) );
}
// Extract the parameters
AllowablePortletSet ap = (AllowablePortletSet)rdata.getUser().getTemp(CustomizerResources.ALLOWABLEPORTLETSET);
AllowableColumnSet ac = (AllowableColumnSet)rdata.getUser().getTemp(CustomizerResources.ALLOWABLECOLUMNSET);
if (ap==null || ac == null)
{
// This occurs when user tried to access this screen out of sequence
rdata.setMessage("WARNING: USER HAS NOT START THE CUSTOMIZATION PROCESS FROM THE BEGINNING.");
return ScreenLoader.getInstance().eval ( rdata, TurbineResources.getString( "screen.mainmenu" ) );
}
ElementContainer ec = new ElementContainer();
ec.addElement(this.buildScript());
// Set the required attributes
rdata.setTitle("GlueCode Customizer Page 2");
rdata.getUser().setTemp(CustomizerResources.PREVIOUSSCREEN, CustomizerResources.CUSTOMIZERSCREEN2);
// Define the main table.
Table mainTable = new Table().setWidth("100%").setBorder(1);
// Add the first row.
TR headerRow = new TR();
headerRow.addElement(new TD().addElement("Left").setAlign("center").setWidth("20%"));
headerRow.addElement(new TD().addElement("Middle").setAlign("center").setWidth("60%"));
headerRow.addElement(new TD().addElement("Right").setAlign("center").setWidth("20%"));
mainTable.addElement(headerRow);
// Add the second row.
mainTable.addElement(this.buildSelectControls(ap));
// Add the third row.
TR thirdRow = new TR();
thirdRow.addElement(new TD().addElement(" "));
thirdRow.addElement(new TD().addElement(this.buildArrowControls()).setAlign("center").setVAlign("middle"));
thirdRow.addElement(new TD().addElement(" "));
//thirdRow.addElement(new TD().addElement(this.buildButtons()).setAlign("center"));
mainTable.addElement(thirdRow);
// Insert the table and the hidden fields into the form.
Form theForm = this.buildForm(rdata).addElement(mainTable);
Input[] hiddenFields = this.buildHiddenFields(ap);
for (int j=0; j<hiddenFields.length; j++)
theForm.addElement(hiddenFields[j]);
theForm.addElement(this.buildColorControls(ac));
theForm.addElement(this.buildButtons());
// insert the form into the element container.
ec.addElement(theForm);
return ec;
}// end doBuild()
/**
* buildSelectControls creates a row (TR) with 3 columns. Each column
* contains a selectControl that has been populated from the
* AllowablePortletSet.
*/
private TR buildSelectControls(AllowablePortletSet ap) throws Exception
{
// Declare the major elements.
TR theRow = new TR();
Select[] selectControls = new Select[3];
// Create the three select controls
for (int i=0; i<selectControls.length; i++)
{
selectControls[i] = new Select();
// Set the size of the control.
selectControls[i].setSize(6);
// Set the name of the controls to be the same as their index numbers.
selectControls[i].setName(String.valueOf(i));
// Add the onChange attribute for Javascript support.
selectControls[i].addAttribute("onChange", "selectEventHandler(this)");
}// end for
// Extract the names of the portlets to be displayed.
String[] portletNames = ap.getUserDefaultPortletNames();
// Sort the portletNames by column and position.
LinkedList sortedNames = new LinkedList();
Comparator portletComparator = new PortletComparator(ap);
for (int i=0; i<portletNames.length; i++)
sortedNames.add(portletNames[i]);
Collections.sort(sortedNames, portletComparator);
for (int i=0; i<portletNames.length; i++)
{
portletNames[i] = (String)sortedNames.get(i);
}
// Populate the select controls. The portlet names _must_ be sorted by
// this point.
for (int i=0; i<portletNames.length; i++)
{
// Create a new option element
int colNumber = ap.getUserDefaultPortletColumn(portletNames[i]);
// Check for portlets that have been added in the previous screen.
if (colNumber == -1)
// Put new portlets at the end of column 0.
colNumber = 0;
Option newOption = new Option(portletNames[i]).setValue(portletNames[i]);
newOption.addElement(ap.getPortletTitle(portletNames[i]));
selectControls[colNumber].addElement(newOption);
}// end for
// Insert the select controls into their own columns in the row.
for (int i=0; i<selectControls.length; i++)
{
// Insert the spacer row
if (i == 1)
selectControls[i].addElement(this.buildSpacer(40));
else
selectControls[i].addElement(this.buildSpacer(20));
theRow.addElement(new TD().addElement(selectControls[i]).setAlign("center"));
}// end for
// Return the row.
return theRow;
}// end buildSelectControls()
/**
* buildHiddenFields creates 2 hidden field elements for each portlet. This
* method returns an array of Input objects.
*/
private Input[] buildHiddenFields(AllowablePortletSet ap) throws Exception
{
// Get the array of portlet names.
String[] portletNames = ap.getUserDefaultPortletNames();
// Instantiate an array of Input objects that is twice as big as the
// portlet names array.
Input[] hiddenFields = new Input[portletNames.length * 2];
// Step through the portlet name array.
for (int i=0; i<portletNames.length; i++) {
Log.note ("CustomizerScreen2: PortletNames[" + i + "] : " + portletNames[i] );
// Create a new hidden field for this portlet's column information.
hiddenFields[i] = new Input();
hiddenFields[i].setType(Input.HIDDEN);
hiddenFields[i].setName(CustomizerResources.COLUMNPREFIX + portletNames[i]);
hiddenFields[i].setValue(ap.getUserDefaultPortletColumn(portletNames[i]));
// Create a new hidden field for this portlet's position information.
// Place the new field at (i + portletNames.length).
hiddenFields[i+portletNames.length] = new Input();
hiddenFields[i+portletNames.length].setType(Input.HIDDEN);
hiddenFields[i+portletNames.length].setName(CustomizerResources.ROWPREFIX + portletNames[i]);
hiddenFields[i+portletNames.length].setValue(ap.getUserDefaultPortletPosition(portletNames[i]));
}// end for
return hiddenFields;
}// end buildHiddenFields()
/**
* buildArrowControls returns a table with the up, down, left and right
* controls embedded in the appropriate cells.
*/
private Table buildArrowControls()
{
// Create the table.
Table theTable = new Table();
// Create the links.
A up = new A().setHref("javascript:moveVertically('up')").addElement("UP");
A dn = new A().setHref("javascript:moveVertically('down')").addElement("DN");
A left = new A().setHref("javascript:moveHorizontally('left')").addElement("<-");
A right = new A().setHref("javascript:moveHorizontally('right')").addElement("->");
// Create the rows
TR row1 = new TR();
TR row2 = new TR();
TR row3 = new TR();
// Populate the rows.
row1.addElement(new TD().setAlign("center").addElement(" "));
row1.addElement(new TD().setAlign("center").addElement(up));
row1.addElement(new TD().setAlign("center").addElement(" "));
row2.addElement(new TD().setAlign("center").addElement(left));
row2.addElement(new TD().setAlign("center").addElement(" "));
row2.addElement(new TD().setAlign("center").addElement(right));
row3.addElement(new TD().setAlign("center").addElement(" "));
row3.addElement(new TD().setAlign("center").addElement(dn));
row3.addElement(new TD().setAlign("center").addElement(" "));
// Add the rows to the table.
theTable.addElement(row1);
theTable.addElement(row2);
theTable.addElement(row3);
return theTable;
}// end buildArrowControls()
/**
* buildButtons returns a table with the submit buttons embedded in it.
*/
private Table buildButtons()
{
// Create the buttons.
Input backBut = new Input(Input.SUBMIT, "eventSubmit_doBack", "Back");
Input cancelBut = new Input(Input.SUBMIT, "eventSubmit_doCancel", "Cancel");
Input submitBut = new Input(Input.SUBMIT, "eventSubmit_doSubmit", "Submit");
Input resetBut = new Input(Input.RESET, "", "Reset");
// Create the table.
Table theTable = new Table();
theTable.setWidth("100%");
// Create an array containing 4 populated table rows.
/*TR[] rows = new TR[4];
rows[0] = new TR().addElement(new TD().addElement(backBut));
rows[1] = new TR().addElement(new TD().addElement(resetBut));
rows[2] = new TR().addElement(new TD().addElement(cancelBut));
rows[3] = new TR().addElement(new TD().addElement(submitBut));
// Add the rows to the table.
for (int i=0; i<rows.length; i++)
theTable.addElement(rows[i]);
*/
TR theRow = new TR();
TD theCell = new TD().addElement(resetBut)
.addElement(cancelBut).addElement(submitBut)
.setAlign("right");
return theTable.addElement(theRow.addElement(theCell));
}// end buildButtons()
/**
* buildForm returns a Form object that has been properly configured for
* this screens needs.
*/
private Form buildForm(RunData rdata)
{
DynamicURI uri = new DynamicURI(rdata);
uri.setAction(CustomizerResources.CUSTOMIZERACTION1);
Form theForm = new Form();
theForm.setName("customizer");
theForm.setAction(uri.toString());
theForm.setMethod("post");
// processForm() refers to a Javascript function that is defined in
// buildScript().
theForm.setOnSubmit("processForm()");
return theForm;
}// end buildForm()
/**
* buildSpacer returns an option object that is used to force the select
* control width. The name of the option is important because the
* Javascript code uses the name of the spacer to prevent users from
* selecting them. The spacer must be the last item in the select control.
*/
private Option buildSpacer(int size)
{
Option theSpacer = new Option().setValue(this.SPACERNAME);
for (int i=0; i<size; i++)
theSpacer.addElement(" ");
return theSpacer;
}// end buildSpacer()
/**
* buildColorControl creates a single select object containing the
* colors defined in the JetspeedColors argument.
*/
private Select buildColorControl(String name, JetspeedColors jc,
String selectedColor)
{
Select newSelect = new Select();
newSelect.setName(name);
for (int i=0; i<jc.getSize(); i++)
{
// Build the option
Option newOption = new Option();
newOption.setValue(jc.getHexColor(i));
newOption.addElement(jc.getColorName(i));
// Check to see if this option is selected.
if (jc.getHexColor(i).equals(selectedColor))
newOption.setSelected(true);
// Insert the option into the select control.
newSelect.addElement(newOption);
}
return newSelect;
}// end buildColorControl()
private Table buildColorControls(AllowableColumnSet ac)
{
JetspeedColors colors = null;
try
{
colors = new JetspeedColors();
}
catch (CustomizerException ce)
{
// do nothing
}
Table colorTable = new Table();
colorTable.setWidth("100%");
colorTable.setBorder(1);
Select[] titleControls = new Select[3];
Select[] bgControls = new Select[3];
try
{
for (int i=0; i<3; i++)
{
titleControls[i] = this.buildColorControl(
CustomizerResources.COLUMNPREFIX + CustomizerResources.HEADINGCOLOR + i,
colors, ac.getColor(i, ac.HEADINGCOLOR));
bgControls[i] = this.buildColorControl(
CustomizerResources.COLUMNPREFIX + CustomizerResources.BACKGROUNDCOLOR
+ i, colors, ac.getColor(i, ac.BACKGROUNDCOLOR));
}// end for
}
catch (Exception e)
{
// do nothing
}
TR heading = new TR();
heading.addElement(new TD().addElement(" "))
.addElement(new TD().addElement("Left").setAlign("center"))
.addElement(new TD().addElement("Middle").setAlign("center"))
.addElement(new TD().addElement("Right").setAlign("center"));
TR row1 = new TR();
row1.addElement(new TD().addElement("Title Color").setAlign("center"));
for (int i=0; i<titleControls.length; i++)
row1.addElement(new TD().addElement(titleControls[i]).setAlign("center"));
TR row2 = new TR();
row2.addElement(new TD().addElement("Background Color").setAlign("center"));
for (int i=0; i<bgControls.length; i++)
row2.addElement(new TD().addElement(bgControls[i]).setAlign("center"));
colorTable.addElement(heading).addElement(row1).addElement(row2);
return colorTable;
}// end buildColorControls()
/**
* buildScript defines the Javascript code that will be placed on the page.
* This method inserts some constant values into the Javascript to ensure
* that the Javascript and the HTML are in sync.
*/
private Script buildScript()
{
Script theScript = new Script();
theScript.setLanguage("Javascript");
theScript.addElement("function swap(theArray, idx1, idx2){");
theScript.addElement(" temp = new Option(theArray[idx1].text, theArray[idx1].value, false, true);");
theScript.addElement(" theArray[idx1].text = theArray[idx2].text;");
theScript.addElement(" theArray[idx1].value = theArray[idx2].value;");
theScript.addElement(" theArray[idx2].text = temp.text;");
theScript.addElement(" theArray[idx2].value = temp.value;");
theScript.addElement(" return theArray;");
theScript.addElement("}");
theScript.addElement("");
theScript.addElement("");
theScript.addElement("function getActiveSelectObject() {");
theScript.addElement(" elements = document."+this.FORMNAME+".elements;");
theScript.addElement(" for (i=0; i<elements.length; i++) {");
theScript.addElement(" if (elements[i].type == \"select-one\" || elements[i].type == \"select-multiple\") {");
theScript.addElement(" if (elements[i].selectedIndex != -1) {");
theScript.addElement(" return elements[i];");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement(" return null;");
theScript.addElement("}");
theScript.addElement("");
theScript.addElement("");
theScript.addElement("function getAdjacentSelectObject(selectObject, direction){");
theScript.addElement(" modifier = 0;");
theScript.addElement(" if (direction == \"right\")");
theScript.addElement(" modifier = 1;");
theScript.addElement(" else");
theScript.addElement(" modifier = -1;");
theScript.addElement(" ");
theScript.addElement(" target = parseInt(selectObject.name) + modifier;");
theScript.addElement(" if (target <= 2 && target >= 0) {");
theScript.addElement(" elements = document."+this.FORMNAME+".elements;");
theScript.addElement(" for (i=0; i<elements.length; i++) {");
theScript.addElement(" if (elements[i].name == target) {");
theScript.addElement(" return elements[i];");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement(" return null;");
theScript.addElement("}");
theScript.addElement("");
theScript.addElement("");
theScript.addElement("function moveHorizontally(direction) {");
theScript.addElement(" from = getActiveSelectObject();");
theScript.addElement(" if (from == null) {");
theScript.addElement(" alert(\"Please select a portlet first.\");");
theScript.addElement(" } else {");
theScript.addElement(" to = getAdjacentSelectObject(from, direction);");
theScript.addElement(" if (to != null) {");
theScript.addElement(" target = new Option(from.options[from.selectedIndex].text, from.options[from.selectedIndex].value,");
theScript.addElement(" false, true);");
theScript.addElement(" from.options[from.selectedIndex] = null;");
theScript.addElement(" myLength = to.options.length;");
theScript.addElement(" to.options[myLength] = new Option(to.options[myLength-1].text, to.options[myLength-1].value,");
theScript.addElement(" false, true);");
theScript.addElement(" to.options[myLength - 1] = new Option(target.text, target.value, false, true);");
theScript.addElement(" to.selectedIndex= myLength-1;");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement("");
theScript.addElement("}");
theScript.addElement("");
theScript.addElement("");
theScript.addElement("function moveVertically(direction) {");
theScript.addElement(" column = getActiveSelectObject();");
theScript.addElement(" if (column == null)");
theScript.addElement(" alert(\"Please select a portlet first.\");");
theScript.addElement(" else {");
theScript.addElement(" idx1 = column.selectedIndex;");
theScript.addElement(" idx2 = -1;");
theScript.addElement(" if (direction == \"up\" && idx1 > 0)");
theScript.addElement(" idx2 = idx1-1;");
theScript.addElement("");
theScript.addElement("");
theScript.addElement("");
theScript.addElement(" if (direction == \"down\" && idx1 < (column.options.length - 2) )");
theScript.addElement(" idx2 = idx1+1;");
theScript.addElement("");
theScript.addElement(" if (idx2 != -1) {");
theScript.addElement(" swap(column.options, idx1, idx2);");
theScript.addElement(" column.selectedIndex = idx2;");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement("}");
theScript.addElement("");
theScript.addElement("");
theScript.addElement("function selectEventHandler(selectObject) {");
theScript.addElement(" ");
theScript.addElement(" for (i=0; i<document."+this.FORMNAME+".elements.length; i++) {");
//theScript.addElement(" if (document."+this.FORMNAME+".elements[i].type == \"select-one\" ||");
//theScript.addElement(" document."+this.FORMNAME+".elements[i].type == \"select-multiple\") {");
theScript.addElement(" if ((document."+this.FORMNAME+".elements[i].type == \"select-one\" ||");
theScript.addElement(" document."+this.FORMNAME+".elements[i].type == \"select-multiple\") && (");
theScript.addElement(" document."+this.FORMNAME+".elements[i].name.substr(0, "
+CustomizerResources.COLUMNPREFIX.length()+") != \""
+CustomizerResources.COLUMNPREFIX+"\")) {");
theScript.addElement(" if (document."+this.FORMNAME+".elements[i].name != selectObject.name) {");
theScript.addElement(" document."+this.FORMNAME+".elements[i].selectedIndex = -1;");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement("");
theScript.addElement(" ");
theScript.addElement(" if (selectObject.selectedIndex != -1) {");
theScript.addElement(" if (selectObject.options[selectObject.selectedIndex].value == \""+this.SPACERNAME+"\") {");
theScript.addElement(" selectObject.selectedIndex=-1;");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement("}");
theScript.addElement("");
theScript.addElement("");
theScript.addElement("function setHiddenValues(name, columnNumber, positionNumber) {");
theScript.addElement(" columnPrefix = \""+CustomizerResources.COLUMNPREFIX+"\";");
theScript.addElement(" positionPrefix = \""+CustomizerResources.ROWPREFIX+"\";");
theScript.addElement(" columnFieldName = columnPrefix + name;");
theScript.addElement(" positionFieldName = positionPrefix + name;");
theScript.addElement(" columnFlag = false;");
theScript.addElement(" positionFlag = false;");
theScript.addElement(" for (k=0; k<document."+this.FORMNAME+".elements.length; k++) {");
theScript.addElement(" if (document."+this.FORMNAME+".elements[k].type == \"hidden\") {");
theScript.addElement(" if (document."+this.FORMNAME+".elements[k].name == columnFieldName) {");
theScript.addElement(" document."+this.FORMNAME+".elements[k].value = columnNumber;");
theScript.addElement(" columnFlag = true;");
theScript.addElement(" }");
theScript.addElement(" if (document."+this.FORMNAME+".elements[k].name == positionFieldName) {");
theScript.addElement(" document."+this.FORMNAME+".elements[k].value = positionNumber;");
theScript.addElement(" positionFlag = true;");
theScript.addElement(" }");
theScript.addElement(" if (columnFlag && positionFlag) {");
theScript.addElement(" return;");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement("}");
theScript.addElement("");
theScript.addElement("");
theScript.addElement("function processForm() {");
theScript.addElement(" for (i=0; i<document."+this.FORMNAME+".elements.length; i++) {");
theScript.addElement(" if ((document."+this.FORMNAME+".elements[i].type == \"select-one\" ||");
theScript.addElement(" document."+this.FORMNAME+".elements[i].type == \"select-multiple\") && (");
theScript.addElement(" document."+this.FORMNAME+".elements[i].name.substr(0, "
+CustomizerResources.COLUMNPREFIX.length()+") != \""
+CustomizerResources.COLUMNPREFIX+"\")) {");
theScript.addElement(" selectObject = document."+this.FORMNAME+".elements[i];");
theScript.addElement(" for (j=0; j< selectObject.options.length; j++){");
theScript.addElement(" if (selectObject.options[j].value==\""+this.SPACERNAME+"\"){");
theScript.addElement(" ");
theScript.addElement(" selectObject.options[j] = null;");
theScript.addElement(" } else {");
theScript.addElement(" ");
theScript.addElement(" setHiddenValues(selectObject.options[j].value, selectObject.name, j);");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement(" ");
theScript.addElement(" document."+this.FORMNAME+".elements[i].selectedIndex = -1;");
theScript.addElement(" }");
theScript.addElement(" }");
theScript.addElement(" return true;");
theScript.addElement("}");
theScript.addElement("");
return theScript;
}
/**
* PortletComparator is a private inner class that compares portlets by
* their Column and position. This is used to sort the portlets.
*/
private class PortletComparator implements Comparator
{
private AllowablePortletSet ap;
public PortletComparator(AllowablePortletSet theAp)
{
this.ap = theAp;
}
public int compare (Object o1, Object o2)
{
String str1 = (String) o1;
String str2 = (String) o2;
int str1Col = -1;
int str2Col = -1;
int str1Pos = -1;
int str2Pos = -1;
try
{
str1Col = this.ap.getUserDefaultPortletColumn(str1);
str1Pos = this.ap.getUserDefaultPortletPosition(str1);
str2Col = this.ap.getUserDefaultPortletColumn(str2);
str2Pos = this.ap.getUserDefaultPortletPosition(str2);
}
catch (Exception e)
{
// do nothing
}// end try-catch
// Check for new portlets. New portlets should be placed at the end.
if ((str1Col == -1 && str2Col != -1) ||
(str2Col == -1 && str1Col != -1))
{
if (str1Col == -1)
return 1;
return -1;
}
else
{
if (str1Col == str2Col)
{
// They are in the same column. Sort by position number.
if (str1Pos == str2Pos)
return 0;
if (str1Pos < str2Pos)
return -1;
if (str1Pos > str2Pos)
return 1;
}// end if
// Sort by column number.
if (str1Col < str2Col)
return -1;
if (str1Col > str2Col)
return 1;
}// end if-else
return 0;
}// end compare()
public boolean equals(Object o1, Object o2)
{
if (this.compare(o1, o2) == 0)
return true;
return false;
}// end equals()
}// end class portletComparator
} //end class GlueCodeCustomizer2
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org