001 package org.apache.myfaces.tobago.component; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020 import org.apache.commons.logging.Log; 021 import org.apache.commons.logging.LogFactory; 022 023 import javax.faces.application.Application; 024 import javax.faces.application.ViewHandler; 025 import javax.faces.context.FacesContext; 026 027 public class Window { 028 029 private static final Log LOG = LogFactory.getLog(Window.class); 030 031 private String viewId; 032 private String name; 033 private int width = 300; 034 private int height = 300; 035 private int left = 100; 036 private int top = 100; 037 private boolean dependent; 038 039 public Window(String viewId) { 040 this.viewId = viewId; 041 } 042 043 public Window(String viewId, int width, int height) { 044 this.viewId = viewId; 045 this.width = width; 046 this.height = height; 047 } 048 049 public Window(String viewId, int width, int heigth, int x, int y) { 050 this.viewId = viewId; 051 this.width = width; 052 this.height = heigth; 053 this.left = x; 054 this.top = y; 055 } 056 057 public void activate(UIPage page) { 058 page.getScriptFiles().add("script/popup.js"); 059 060 FacesContext facesContext = FacesContext.getCurrentInstance(); 061 Application application = facesContext.getApplication(); 062 ViewHandler viewHandler = application.getViewHandler(); 063 String actionUrl = viewHandler.getActionURL(facesContext, viewId); 064 actionUrl = facesContext.getExternalContext().encodeActionURL(actionUrl); 065 if (LOG.isDebugEnabled()) { 066 LOG.debug("actionUrl = '" + actionUrl + "'"); 067 } 068 069 StringBuilder buffer = new StringBuilder(); 070 buffer.append("openPopup('"); 071 buffer.append(actionUrl); 072 buffer.append("', '"); 073 buffer.append(name); 074 buffer.append("', '"); 075 buffer.append(width); 076 buffer.append("', '"); 077 buffer.append(height); 078 buffer.append("', '"); 079 if (dependent) { 080 buffer.append('p'); 081 } 082 buffer.append("', '"); 083 buffer.append(left); 084 buffer.append("', '"); 085 buffer.append(top); 086 buffer.append("');"); 087 page.getOnloadScripts().add(buffer.toString()); 088 } 089 090 public String getViewId() { 091 return viewId; 092 } 093 094 public void setViewId(String viewId) { 095 this.viewId = viewId; 096 } 097 098 public String getName() { 099 return name; 100 } 101 102 public void setName(String name) { 103 this.name = name; 104 } 105 106 public int getWidth() { 107 return width; 108 } 109 110 public void setWidth(int width) { 111 this.width = width; 112 } 113 114 public int getHeight() { 115 return height; 116 } 117 118 public void setHeight(int height) { 119 this.height = height; 120 } 121 122 public int getLeft() { 123 return left; 124 } 125 126 public void setLeft(int left) { 127 this.left = left; 128 } 129 130 public int getTop() { 131 return top; 132 } 133 134 public void setTop(int top) { 135 this.top = top; 136 } 137 138 public boolean isDependent() { 139 return dependent; 140 } 141 142 public void setDependent(boolean dependent) { 143 this.dependent = dependent; 144 } 145 } 146