. Checkpoint of WCM UI

- More implementation of the User sandboxes UI
   - added actions placeholders for Preview, Create and Browse for sandbox
   - Modified files list component framework and placeholder
 - Import Website Content dialog component framework pieces

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3791 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-09-14 14:18:26 +00:00
parent 66803daad8
commit 64f50671da
10 changed files with 605 additions and 50 deletions

View File

@@ -0,0 +1,188 @@
/*
* Copyright (C) 2005 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.web.bean.wcm;
import java.io.File;
import java.text.MessageFormat;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.transaction.UserTransaction;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.FileUploadBean;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
/**
* @author Kevin Roast
*/
public class ImportWebsiteDialog
{
protected File file;
protected String fileName;
private boolean isFinished = false;
/**
* @return Returns the name of the file
*/
public String getFileName()
{
// try and retrieve the file and filename from the file upload bean
// representing the file we previously uploaded.
FacesContext ctx = FacesContext.getCurrentInstance();
FileUploadBean fileBean = (FileUploadBean)ctx.getExternalContext().getSessionMap().
get(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
if (fileBean != null)
{
this.file = fileBean.getFile();
this.fileName = fileBean.getFileName();
}
return this.fileName;
}
/**
* @param fileName The name of the file
*/
public void setFileName(String fileName)
{
this.fileName = fileName;
// we also need to keep the file upload bean in sync
FacesContext ctx = FacesContext.getCurrentInstance();
FileUploadBean fileBean = (FileUploadBean)ctx.getExternalContext().getSessionMap().
get(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
if (fileBean != null)
{
fileBean.setFileName(this.fileName);
}
}
public boolean getFinishButtonDisabled()
{
return (this.fileName == null || this.fileName.length() == 0);
}
// ------------------------------------------------------------------------------
// Action event handlers
/**
* Action listener called when the add content dialog is called
*/
public void start(ActionEvent event)
{
clearUpload();
this.fileName = null;
}
/**
* Action handler called when the Finish button is pressed
*/
public String finish()
{
String outcome = null;
// check the isFinished flag to stop the finish button
// being pressed multiple times
if (this.isFinished == false)
{
this.isFinished = true;
UserTransaction tx = null;
try
{
FacesContext context = FacesContext.getCurrentInstance();
tx = Repository.getUserTransaction(context);
tx.begin();
//
// TODO: import the content
//
tx.commit();
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
catch (Throwable e)
{
// rollback the transaction
try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
Utils.addErrorMessage(MessageFormat.format(
Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC),
e.getMessage(), e));
}
finally
{
// reset the flag so we can re-attempt the operation
this.isFinished = false;
}
}
return outcome;
}
/**
* Action handler called when the user wishes to remove an uploaded file
*/
public String removeUploadedFile()
{
clearUpload();
// also clear the file name
this.fileName = null;
// refresh the current page
return null;
}
/**
* Action handler called when the dialog is cancelled
*/
public String cancel()
{
clearUpload();
return AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
}
// ------------------------------------------------------------------------------
// Helper Methods
/**
* Deletes the uploaded file and removes the FileUploadBean from the session
*/
protected void clearUpload()
{
// delete the temporary file we uploaded earlier
if (this.file != null)
{
this.file.delete();
}
this.file = null;
// remove the file upload bean from the session
FacesContext ctx = FacesContext.getCurrentInstance();
ctx.getExternalContext().getSessionMap().remove(FileUploadBean.FILE_UPLOAD_BEAN_NAME);
}
}

View File

@@ -64,10 +64,11 @@ public class UIActions extends SelfRenderingComponent
private static final String ATTR_STYLECLASS = "styleClass";
private static final String ATTR_STYLE = "style";
private static final String ACTION_CONTEXT = "actionContext";
private static final String RENDERER_ACTIONLINK = "org.alfresco.faces.ActionLinkRenderer";
private static final String COMPONENT_ACTIONLINK = "org.alfresco.faces.ActionLink";
private static final String COMPONENT_PERMISSIONEVAL = "org.alfresco.faces.PermissionEvaluator";
private static final String COMPONENT_ACTIONEVAL = "org.alfresco.faces.ActionInstanceEvaluator";
public static final String RENDERER_ACTIONLINK = "org.alfresco.faces.ActionLinkRenderer";
public static final String COMPONENT_ACTIONLINK = "org.alfresco.faces.ActionLink";
public static final String COMPONENT_PERMISSIONEVAL = "org.alfresco.faces.PermissionEvaluator";
public static final String COMPONENT_ACTIONEVAL = "org.alfresco.faces.ActionInstanceEvaluator";
private final static Class ACTION_CLASS_ARGS[] = {javax.faces.event.ActionEvent.class};

View File

@@ -19,8 +19,10 @@ package org.alfresco.web.ui.wcm.component;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import javax.faces.component.NamingContainer;
@@ -42,15 +44,23 @@ import org.alfresco.web.bean.wcm.AVMConstants;
import org.alfresco.web.ui.common.PanelGenerator;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.SelfRenderingComponent;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.alfresco.web.ui.repo.component.UIActions;
import org.alfresco.web.ui.wcm.WebResources;
import org.springframework.web.jsf.FacesContextUtils;
import sun.swing.UIAction;
/**
* @author Kevin Roast
*/
public class UIUserSandboxes extends SelfRenderingComponent
{
private static final String MSG_USERNAME = "username";
private static final String MSG_NAME = "name";
private static final String MSG_DESCRIPTION = "description";
private static final String MSG_MODIFIED = "modified_date";
private static final String MSG_ACTIONS = "actions";
/** website to show sandboxes for */
private NodeRef value;
@@ -87,6 +97,22 @@ public class UIUserSandboxes extends SelfRenderingComponent
values[2] = this.expandedPanels;
return values;
}
/**
* @see javax.faces.component.UIComponentBase#getRendersChildren()
*/
public boolean getRendersChildren()
{
return true;
}
/**
* @see javax.faces.component.UIComponentBase#encodeChildren(javax.faces.context.FacesContext)
*/
public void encodeChildren(FacesContext context) throws IOException
{
// the child components are rendered explicitly during the encodeBegin()
}
/**
* @see javax.faces.component.UIComponentBase#decode(javax.faces.context.FacesContext)
@@ -127,11 +153,7 @@ public class UIUserSandboxes extends SelfRenderingComponent
ResponseWriter out = context.getResponseWriter();
if (getChildCount() == 0)
{
// create any sub-component for the first time
}
ResourceBundle bundle = Application.getBundle(context);
AVMService avmService = getAVMService(context);
NodeService nodeService = getNodeService(context);
UserTransaction tx = null;
@@ -153,45 +175,92 @@ public class UIUserSandboxes extends SelfRenderingComponent
{
String username = users.get(i);
// build the name of the main store for the user
String mainStore = storeRoot + '-' + username + AVMConstants.STORE_MAIN;
AVMStoreDescriptor store = avmService.getAVMStore(mainStore);
// for each user sandbox, generate an outer panel table
PanelGenerator.generatePanelStart(out,
context.getExternalContext().getRequestContextPath(),
"white",
"white");
// components for the current username, preview, browse and modified items inner list
out.write("<table cellspacing=2 cellpadding=2 border=0 width=100%><tr><td>");
out.write(Utils.buildImageTag(context, WebResources.IMAGE_SANDBOX_32, 32, 32, ""));
out.write("</td><td width=100%>");
out.write("<b>");
out.write(Application.getMessage(context, MSG_USERNAME));
out.write(":</b>&nbsp;");
out.write(username); // TODO: convert to full name
out.write("</td><td><nobr>");
// direct actions for a sandbox
// TODO: add actions for a sandbox
out.write("(Preview) (Create) (Browse)");
out.write("</nobr></td></tr>");
// modified items panel
out.write("<tr><td></td><td colspan=2>");
String panelImage = this.expandedPanels.contains(username) ? WebResources.IMAGE_EXPANDED : WebResources.IMAGE_COLLAPSED;
out.write(Utils.buildImageTag(context, panelImage, 11, 11, "",
Utils.generateFormSubmit(context, this, getClientId(context), username)));
out.write("&nbsp;<b>Modified Items (3)</b>");
out.write("</td></tr></table>");
// end the outer panel for this sandbox
PanelGenerator.generatePanelEnd(out,
context.getExternalContext().getRequestContextPath(),
"white");
// spacer row
if (i < users.size() - 1)
// check it exists before we render the view
if (avmService.getAVMStore(mainStore) != null)
{
out.write("<div style='padding:4px'></div>");
// for each user sandbox, generate an outer panel table
PanelGenerator.generatePanelStart(out,
context.getExternalContext().getRequestContextPath(),
"white",
"white");
// components for the current username, preview, browse and modified items inner list
out.write("<table cellspacing=2 cellpadding=2 border=0 width=100%><tr><td>");
out.write(Utils.buildImageTag(context, WebResources.IMAGE_SANDBOX_32, 32, 32, ""));
out.write("</td><td width=100%>");
out.write("<b>");
out.write(bundle.getString(MSG_USERNAME));
out.write(":</b>&nbsp;");
out.write(username); // TODO: convert to full name?
out.write("</td><td><nobr>");
// direct actions for a sandbox
Utils.encodeRecursive(context, aquireAction(
context, "sandbox_preview", "/images/icons/preview_website.gif"));
out.write("&nbsp;&nbsp;");
Utils.encodeRecursive(context, aquireAction(
context, "sandbox_create", "/images/icons/new_content.gif"));
out.write("&nbsp;&nbsp;");
Utils.encodeRecursive(context, aquireAction(
context, "sandbox_browse", "/images/icons/space_small.gif"));
out.write("</nobr></td></tr>");
// modified items panel
out.write("<tr><td></td><td colspan=2>");
String panelImage = WebResources.IMAGE_COLLAPSED;
if (this.expandedPanels.contains(username))
{
panelImage = WebResources.IMAGE_EXPANDED;
}
out.write(Utils.buildImageTag(context, panelImage, 11, 11, "",
Utils.generateFormSubmit(context, this, getClientId(context), username)));
out.write("&nbsp;<b>Modified Items (3)</b>");
if (this.expandedPanels.contains(username))
{
out.write("<div style='padding:2px'></div>");
out.write("<table cellspacing=2 cellpadding=2 border=0 width=100%>");
// header row
out.write("<tr align=left><th width=16></th><th>");
out.write(bundle.getString(MSG_NAME));
out.write("</th><th>");
out.write(bundle.getString(MSG_DESCRIPTION));
out.write("</th><th>");
out.write(bundle.getString(MSG_MODIFIED));
out.write("</th><th>");
out.write(bundle.getString(MSG_ACTIONS));
out.write("</th></tr>");
// row per modified doc item
// TODO: add modified items list for this sandbox user
out.write("<tr><td width=16>(O)</td><td>");
out.write("Some document.html");
out.write("</td><td>");
out.write("A description would go here");
out.write("</td><td>");
out.write("01-01-2006 11:58am");
out.write("</td><td>");
// TODO: add UI actions for this item
out.write("(P)&nbsp;(E)&nbsp;(T)&nbsp;(D)");
out.write("</td></tr>");
out.write("</table>");
}
out.write("</td></tr></table>");
// end the outer panel for this sandbox
PanelGenerator.generatePanelEnd(out,
context.getExternalContext().getRequestContextPath(),
"white");
// spacer row
if (i < users.size() - 1)
{
out.write("<div style='padding:4px'></div>");
}
}
}
@@ -204,6 +273,47 @@ public class UIUserSandboxes extends SelfRenderingComponent
}
}
private UIActionLink aquireAction(FacesContext fc, String name, String icon)
{
UIActionLink action = findAction(name);
if (action == null)
{
action = createAction(fc, name, icon);
}
return action;
}
private UIActionLink findAction(String name)
{
UIActionLink action = null;
String actionId = getId() + name;
for (UIComponent component : (List<UIComponent>)getChildren())
{
if (actionId.equals(component.getId()))
{
action = (UIActionLink)component;
break;
}
}
return action;
}
private UIActionLink createAction(FacesContext fc, String name, String icon)
{
javax.faces.application.Application facesApp = fc.getApplication();
UIActionLink control = (UIActionLink)facesApp.createComponent(UIActions.COMPONENT_ACTIONLINK);
control.setRendererType(UIActions.RENDERER_ACTIONLINK);
control.setId(getId() + name);
control.setValue(Application.getMessage(fc, name));
control.setShowLink(false);
control.setImage(icon);
this.getChildren().add(control);
return control;
}
private AVMService getAVMService(FacesContext fc)
{
return (AVMService)FacesContextUtils.getRequiredWebApplicationContext(fc).getBean("AVMService");