1.1 --- a/visualweb.project.jsf/src/org/netbeans/modules/visualweb/project/jsf/actions/SetStartPageAction.java Fri Apr 04 10:20:42 2008 -0700
1.2 +++ b/visualweb.project.jsf/src/org/netbeans/modules/visualweb/project/jsf/actions/SetStartPageAction.java Fri Apr 04 17:10:51 2008 -0700
1.3 @@ -39,44 +39,26 @@
1.4 * made subject to such option by the copyright holder.
1.5 */
1.6
1.7 -
1.8 package org.netbeans.modules.visualweb.project.jsf.actions;
1.9
1.10 -import org.netbeans.modules.visualweb.project.jsf.api.JsfPortletSupport;
1.11 -import org.netbeans.modules.visualweb.project.jsf.api.JsfPortletSupportException;
1.12 import org.netbeans.modules.visualweb.project.jsf.api.JsfProjectUtils;
1.13
1.14 import java.awt.event.ActionEvent;
1.15 import javax.swing.Action;
1.16 import javax.swing.AbstractAction;
1.17 +import javax.swing.JMenuItem;
1.18
1.19 import org.openide.ErrorManager;
1.20 -import org.openide.awt.StatusDisplayer;
1.21 import org.openide.filesystems.FileObject;
1.22 import org.openide.loaders.DataObject;
1.23 +import org.openide.awt.Mnemonics;
1.24 +import org.openide.awt.StatusDisplayer;
1.25 import org.openide.util.ContextAwareAction;
1.26 import org.openide.util.Lookup;
1.27 import org.openide.util.NbBundle;
1.28 -
1.29 +import org.openide.util.actions.Presenter;
1.30 import org.netbeans.api.project.FileOwnerQuery;
1.31 import org.netbeans.api.project.Project;
1.32 -import org.netbeans.modules.visualweb.api.portlet.dd.PortletModeType;
1.33 -import java.awt.event.ActionListener;
1.34 -import java.awt.event.KeyEvent;
1.35 -import java.io.File;
1.36 -import java.io.IOException;
1.37 -import javax.swing.ButtonGroup;
1.38 -import javax.swing.JMenu;
1.39 -import javax.swing.JMenuItem;
1.40 -import javax.swing.JRadioButtonMenuItem;
1.41 -import javax.swing.event.MenuEvent;
1.42 -import javax.swing.event.MenuListener;
1.43 -import org.openide.awt.JMenuPlus;
1.44 -import org.openide.awt.Mnemonics;
1.45 -import org.openide.filesystems.FileUtil;
1.46 -import org.openide.loaders.DataNode;
1.47 -import org.openide.loaders.DataObjectNotFoundException;
1.48 -import org.openide.util.actions.Presenter;
1.49
1.50
1.51 /**
1.52 @@ -86,338 +68,83 @@
1.53 * @author Peter Zavadsky (refactored previous actions)
1.54 * @author Mark Dey (originally action for jsp)
1.55 * @author David Botterill (originally action for portlet)
1.56 + * @author Po-Ting Wu
1.57 */
1.58 -public class SetStartPageAction extends AbstractAction
1.59 - implements Presenter.Menu, Presenter.Popup, ContextAwareAction {
1.60 +public class SetStartPageAction extends AbstractAction implements Presenter.Menu, Presenter.Popup, ContextAwareAction {
1.61
1.62 private static final int TYPE_NONE = 0;
1.63 private static final int TYPE_JSP = 1;
1.64 private static final int TYPE_PORTLET = 2;
1.65
1.66 private final int type;
1.67 -
1.68 private final FileObject fo;
1.69 - private final DataObject dataObject;
1.70 -
1.71
1.72 /** Creates a new instance of SetStartPageAction */
1.73 public SetStartPageAction() {
1.74 this(TYPE_NONE, null); // Fake action -> The context aware is real one, drawback of the NB design?
1.75 }
1.76
1.77 - private SetStartPageAction(int type, DataObject inDataObject) {
1.78 + private SetStartPageAction(int type, FileObject fo) {
1.79 + super((type == TYPE_JSP) ? NbBundle.getMessage(SetStartPageAction.class, "LBL_SetAsStartPage") : null);
1.80 +
1.81 this.type = type;
1.82 - this.dataObject = inDataObject;
1.83 -
1.84 - if(null != inDataObject) {
1.85 - this.fo = dataObject.getPrimaryFile();
1.86 - } else this.fo = null;
1.87 -
1.88 - String name;
1.89 - if(type == TYPE_JSP) {
1.90 - name = NbBundle.getMessage(SetStartPageAction.class, "LBL_SetAsStartPage");
1.91 - } else if(type == TYPE_PORTLET) {
1.92 - name = NbBundle.getMessage(SetStartPageAction.class, "LBL_SetInitalPageAction_SETINITIALVIEWPAGE");
1.93 - } else {
1.94 - name = null;
1.95 - }
1.96 - putValue(Action.NAME, name);
1.97 + this.fo = fo;
1.98 }
1.99
1.100 public void actionPerformed(ActionEvent evt) {
1.101 - if(type == TYPE_JSP) {
1.102 - // Copy from previous SetAsStartPageAction (Mark)
1.103 + if (type == TYPE_JSP) {
1.104 String newStartPage = JsfProjectUtils.setStartPage(fo);
1.105 String msg = newStartPage != null ?
1.106 NbBundle.getMessage(SetStartPageAction.class, "MSG_StartPageChanged") + " " + newStartPage :
1.107 NbBundle.getMessage(SetStartPageAction.class, "MSG_NoStartPage");
1.108
1.109 StatusDisplayer.getDefault().setStatusText(msg);
1.110 - } else if(type == TYPE_PORTLET) {
1.111 - // Copy from previous SetInitialPageAction (David)
1.112 - Project project = FileOwnerQuery.getOwner(fo);
1.113 - if (project == null)
1.114 - return;
1.115 - JsfPortletSupport portletSupport = JsfProjectUtils.getPortletSupport(project);
1.116 - if (portletSupport == null) return;
1.117 - String actionCommand = evt.getActionCommand();
1.118 -
1.119 - try {
1.120 - /**
1.121 - * Fix for CR 6337056. Need to get the root path to the JSP files to be able
1.122 - * to set the currently set initial page icon back to the default one.
1.123 - * -David Botterill 10/14/2005
1.124 - */
1.125 - /**
1.126 - * We need the path to the JSP root directory so we can use it to set the icons.
1.127 - */
1.128 -
1.129 - FileObject jspRootFO = JsfProjectUtils.getDocumentRoot(project);
1.130 - File jspRootFile = FileUtil.toFile(jspRootFO);
1.131 - String dataNodePath = null;
1.132 - try {
1.133 - dataNodePath = jspRootFile.getCanonicalPath();
1.134 - } catch (IOException ioe) {
1.135 - ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ioe);
1.136 - }
1.137 - if(actionCommand.equals(NbBundle.getMessage(SetStartPageAction.class, "MNU_VIEWMODE"))) {
1.138 - /**
1.139 - * Set the icon for the current one for this mode to the default icon.
1.140 - */
1.141 - String currentViewPage = portletSupport.getInitialPage(PortletModeType.VIEW);
1.142 - if(null != currentViewPage) {
1.143 - FileObject currentFO = FileUtil.toFileObject(new File(dataNodePath + File.separator + currentViewPage));
1.144 - /**
1.145 - * Fix for CR 6329425
1.146 - * Make sure the page is found since the user may have deleted the page after they set the initial
1.147 - * mode.
1.148 - * -David Botterill 9/28/2005
1.149 - */
1.150 - if(null != currentFO) {
1.151 - try {
1.152 - DataObject currentDO = DataObject.find(currentFO);
1.153 - ((DataNode)currentDO.getNodeDelegate()).setIconBase("org/netbeans/modules/visualweb/project/jsfloader/resources/jsfJspObject.gif"); //NOI18N
1.154 - } catch(DataObjectNotFoundException donfe) {
1.155 - NbBundle.getMessage(SetStartPageAction.class,
1.156 - "MSG_UnableToSetDefaultIcon", currentViewPage);
1.157 - }
1.158 - }
1.159 -
1.160 - }
1.161 - portletSupport.setInitialPage(PortletModeType.VIEW, fo);
1.162 - /**
1.163 - * Now set the right data node with the mode icon.
1.164 - */
1.165 - ((DataNode)dataObject.getNodeDelegate()).setIconBase("org/netbeans/modules/visualweb/project/jsfloader/resources/initialviewpage.png"); //NOI18N
1.166 - ((DataNode)dataObject.getNodeDelegate()).setShortDescription(NbBundle.getMessage(SetStartPageAction.class, "LBL_InitialViewShortDesc"));
1.167 - } else if(actionCommand.equals(NbBundle.getMessage(SetStartPageAction.class, "MNU_EDITMODE"))) {
1.168 - /**
1.169 - * Set the icon for the current one for this mode to the default icon.
1.170 - */
1.171 - String currentEditPage = portletSupport.getInitialPage(PortletModeType.EDIT);
1.172 - if(null != currentEditPage) {
1.173 - FileObject currentFO = FileUtil.toFileObject(new File(dataNodePath + File.separator + currentEditPage));
1.174 - /**
1.175 - * Fix for CR 6329425
1.176 - * Make sure the page is found since the user may have deleted the page after they set the initial
1.177 - * mode.
1.178 - * -David Botterill 9/28/2005
1.179 - */
1.180 - if(null != currentFO) {
1.181 - try {
1.182 - DataObject currentDO = DataObject.find(currentFO);
1.183 - ((DataNode)currentDO.getNodeDelegate()).setIconBase("org/netbeans/modules/visualweb/project/jsfloader/resources/jsfJspObject.gif"); //NOI18N
1.184 - } catch(DataObjectNotFoundException donfe) {
1.185 - NbBundle.getMessage(SetStartPageAction.class,
1.186 - "MSG_UnableToSetDefaultIcon", currentEditPage);
1.187 - }
1.188 - }
1.189 -
1.190 - }
1.191 - portletSupport.setInitialPage(PortletModeType.EDIT, fo);
1.192 - /**
1.193 - * Now set the right data node with the mode icon.
1.194 - */
1.195 - ((DataNode)dataObject.getNodeDelegate()).setIconBase("org/netbeans/modules/visualweb/project/jsfloader/resources/initialeditpage.png");//NOI18N
1.196 - ((DataNode)dataObject.getNodeDelegate()).setShortDescription(NbBundle.getMessage(SetStartPageAction.class, "LBL_InitialEditShortDesc"));
1.197 - } else if(actionCommand.equals(NbBundle.getMessage(SetStartPageAction.class, "MNU_HELPMODE"))) {
1.198 - /**
1.199 - * Set the icon for the current one for this mode to the default icon.
1.200 - */
1.201 - String currentHelpPage = portletSupport.getInitialPage(PortletModeType.HELP);
1.202 - FileObject currentFO = FileUtil.toFileObject(new File(dataNodePath + File.separator + currentHelpPage));
1.203 - /**
1.204 - * Fix for CR 6329425
1.205 - * Make sure the page is found since the user may have deleted the page after they set the initial
1.206 - * mode.
1.207 - * -David Botterill 9/28/2005
1.208 - */
1.209 - if(null != currentFO) {
1.210 - try {
1.211 - DataObject currentDO = DataObject.find(currentFO);
1.212 - ((DataNode)currentDO.getNodeDelegate()).setIconBase("org/netbeans/modules/visualweb/project/jsfloader/resources/jsfJspObject.gif"); //NOI18N
1.213 - } catch(DataObjectNotFoundException donfe) {
1.214 - NbBundle.getMessage(SetStartPageAction.class,
1.215 - "MSG_UnableToSetDefaultIcon", currentHelpPage);
1.216 - }
1.217 - }
1.218 - portletSupport.setInitialPage(PortletModeType.HELP, fo);
1.219 -
1.220 - /**
1.221 - * Now set the right data node with the mode icon.
1.222 - */
1.223 - ((DataNode)dataObject.getNodeDelegate()).setIconBase("org/netbeans/modules/visualweb/project/jsfloader/resources/initialhelppage.png");//NOI18N
1.224 - ((DataNode)dataObject.getNodeDelegate()).setShortDescription(NbBundle.getMessage(SetStartPageAction.class, "LBL_InitialHelpShortDesc"));
1.225 - } else if(actionCommand.equals(NbBundle.getMessage(SetStartPageAction.class, "MNU_NONEMODE"))) {
1.226 - /**
1.227 - * Unset the page as an initial page.
1.228 - */
1.229 - portletSupport.unsetInitialPage(fo);
1.230 -
1.231 - /**
1.232 - * Now set the icon to the default icon.
1.233 - */
1.234 - try {
1.235 - DataObject currentDO = DataObject.find(fo);
1.236 - ((DataNode)currentDO.getNodeDelegate()).setIconBase("org/netbeans/modules/visualweb/project/jsfloader/resources/jsfJspObject.gif"); //NOI18N
1.237 - } catch(DataObjectNotFoundException donfe) {
1.238 - NbBundle.getMessage(SetStartPageAction.class,
1.239 - "MSG_UnableToSetDefaultIcon", fo.getNameExt());
1.240 - }
1.241 -
1.242 -
1.243 - }
1.244 - } catch(JsfPortletSupportException jpse) {
1.245 - ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, jpse);
1.246 - }
1.247 }
1.248 }
1.249
1.250 public Action createContextAwareInstance(Lookup context) {
1.251 DataObject dob = (DataObject)context.lookup(DataObject.class);
1.252
1.253 - if(dob == null) {
1.254 + if (dob == null) {
1.255 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
1.256 new IllegalStateException("SetStartPageAction: missing DataObject instance in the context, context=" + context)); // NOI18N
1.257 return null;
1.258 }
1.259
1.260 -
1.261 + int type = TYPE_JSP;
1.262 FileObject fo = dob.getPrimaryFile();
1.263 - if(isJspInPortletProject(fo)) {
1.264 - return new SetStartPageAction(TYPE_PORTLET, dob);
1.265 - } else {
1.266 - return new SetStartPageAction(TYPE_JSP, dob);
1.267 + // check for jsp extension
1.268 + if ((fo != null) && "jsp".equalsIgnoreCase(fo.getExt())) { // NOI18N
1.269 + // check if this is a portlet project
1.270 + Project thisProj = FileOwnerQuery.getOwner(fo);
1.271 + if (JsfProjectUtils.getPortletSupport(thisProj) != null) {
1.272 + type = TYPE_PORTLET;
1.273 + }
1.274 }
1.275 +
1.276 + return new SetStartPageAction(type, fo);
1.277 }
1.278 - // Implementation of Presenter.Menu -----------------------------------
1.279
1.280 public JMenuItem getMenuPresenter() {
1.281 - if(isJspInPortletProject(fo)) {
1.282 - JMenu mainItem = new JMenuPlus();
1.283 - String name = NbBundle.getMessage(SetStartPageAction.class, "LBL_SetInitalPageAction_SETINITIALVIEWPAGE");
1.284 - Mnemonics.setLocalizedText(mainItem,
1.285 - name);
1.286 - mainItem.addMenuListener(new InitialItemListener(this));
1.287 -
1.288 - return mainItem;
1.289 - } else {
1.290 - JMenuItem mainItem = new JMenuItem();
1.291 + return getPresenter();
1.292 + }
1.293 +
1.294 + public JMenuItem getPopupPresenter() {
1.295 + return getPresenter();
1.296 + }
1.297 +
1.298 + public JMenuItem getPresenter() {
1.299 + JMenuItem mainItem = new JMenuItem();
1.300 +
1.301 + if (type == TYPE_JSP) {
1.302 String name = NbBundle.getMessage(SetStartPageAction.class, "LBL_SetAsStartPage");
1.303 mainItem.setEnabled(!(JsfProjectUtils.isStartPage(fo) || fo.getExt().equalsIgnoreCase("jspf")));
1.304 - Mnemonics.setLocalizedText(mainItem,
1.305 - name);
1.306 + Mnemonics.setLocalizedText(mainItem, name);
1.307 mainItem.addActionListener(this);
1.308 - return mainItem;
1.309 + } else {
1.310 + mainItem.setVisible(false);
1.311 }
1.312 +
1.313 + return mainItem;
1.314 }
1.315 -
1.316 - // Implementation of Presenter.Popup ----------------------------------
1.317 -
1.318 - public JMenuItem getPopupPresenter() {
1.319 - if(isJspInPortletProject(fo)) {
1.320 - JMenu mainItem = new JMenuPlus();
1.321 - String name = NbBundle.getMessage(SetStartPageAction.class, "LBL_SetInitalPageAction_SETINITIALVIEWPAGE");
1.322 - Mnemonics.setLocalizedText(mainItem,
1.323 - name);
1.324 - mainItem.addMenuListener(new InitialItemListener(this));
1.325 -
1.326 - return mainItem;
1.327 - } else {
1.328 - JMenuItem mainItem = new JMenuItem();
1.329 - String name = NbBundle.getMessage(SetStartPageAction.class, "LBL_SetAsStartPage");
1.330 - mainItem.setEnabled(!(JsfProjectUtils.isStartPage(fo) || fo.getExt().equalsIgnoreCase("jspf")));
1.331 - Mnemonics.setLocalizedText(mainItem,
1.332 - name);
1.333 - mainItem.addActionListener(this);
1.334 - return mainItem;
1.335 - }
1.336 - }
1.337 -
1.338 - private static boolean isJspInPortletProject(FileObject fo){
1.339 - //check for jsp extension
1.340 - if(fo.getExt().compareToIgnoreCase("jsp") == 0){ // NOI18N
1.341 - //check if this is a portlet project
1.342 - Project thisProj = FileOwnerQuery.getOwner(fo);
1.343 - if(JsfProjectUtils.getPortletSupport(thisProj) != null) {
1.344 - return true;
1.345 - }
1.346 - }
1.347 - return false;
1.348 - }
1.349 -
1.350 - /** Listens to selection of the INITIAL menu item and expands it
1.351 - * into a submenu listing INITIAL modes.
1.352 - */
1.353 - private class InitialItemListener implements MenuListener {
1.354 - ActionListener actionListener;
1.355 -
1.356 - public InitialItemListener(ActionListener inListener) {
1.357 - this.actionListener = inListener;
1.358 - }
1.359 -
1.360 - public void menuCanceled(MenuEvent e) {
1.361 - }
1.362 -
1.363 - public void menuDeselected(MenuEvent e) {
1.364 - JMenu menu = (JMenu)e.getSource();
1.365 - menu.removeAll();
1.366 - }
1.367 -
1.368 - public void menuSelected(MenuEvent e) {
1.369 - JMenu menu = (JMenu)e.getSource();
1.370 - ButtonGroup group = new ButtonGroup();
1.371 -
1.372 - JRadioButtonMenuItem rbViewItem = new JRadioButtonMenuItem(NbBundle.getMessage(SetStartPageAction.class, "MNU_VIEWMODE"));
1.373 - rbViewItem.addActionListener(actionListener);
1.374 - group.add(rbViewItem);
1.375 - menu.add(rbViewItem);
1.376 - rbViewItem.setMnemonic(NbBundle.getMessage(SetStartPageAction.class, "MNE_VIEWMODE").charAt(0));
1.377 -
1.378 - JRadioButtonMenuItem rbEditItem = new JRadioButtonMenuItem(NbBundle.getMessage(SetStartPageAction.class, "MNU_EDITMODE"));
1.379 - rbEditItem.addActionListener(actionListener);
1.380 - group.add(rbEditItem);
1.381 - menu.add(rbEditItem);
1.382 - rbEditItem.setMnemonic(NbBundle.getMessage(SetStartPageAction.class, "MNE_EDITMODE").charAt(0));
1.383 -
1.384 - JRadioButtonMenuItem rbHelpItem = new JRadioButtonMenuItem(NbBundle.getMessage(SetStartPageAction.class, "MNU_HELPMODE"));
1.385 - rbHelpItem.addActionListener(actionListener);
1.386 - group.add(rbHelpItem);
1.387 - menu.add(rbHelpItem);
1.388 - rbHelpItem.setMnemonic(NbBundle.getMessage(SetStartPageAction.class, "MNE_HELPMODE").charAt(0));
1.389 -
1.390 -
1.391 - JRadioButtonMenuItem rbNoneItem = new JRadioButtonMenuItem(NbBundle.getMessage(SetStartPageAction.class, "MNU_NONEMODE"));
1.392 - rbNoneItem.addActionListener(actionListener);
1.393 - group.add(rbNoneItem);
1.394 - menu.add(rbNoneItem);
1.395 - rbNoneItem.setMnemonic(NbBundle.getMessage(SetStartPageAction.class, "MNE_NONEMODE").charAt(0));
1.396 -
1.397 - /**
1.398 - * Now set the one that is currently selected.
1.399 - */
1.400 - Project project = FileOwnerQuery.getOwner(fo);
1.401 - if (project == null)
1.402 - return;
1.403 - JsfPortletSupport portletSupport = JsfProjectUtils.getPortletSupport(project);
1.404 - if(null == portletSupport) return;
1.405 - try {
1.406 - if(portletSupport.isInitialPage(PortletModeType.VIEW, fo)) {
1.407 - rbViewItem.setSelected(true);
1.408 - } else if(portletSupport.isInitialPage(PortletModeType.EDIT, fo)) {
1.409 - rbEditItem.setSelected(true);
1.410 - } else if(portletSupport.isInitialPage(PortletModeType.HELP, fo)) {
1.411 - rbHelpItem.setSelected(true);
1.412 - } else {
1.413 - rbNoneItem.setSelected(true);
1.414 - }
1.415 - } catch(JsfPortletSupportException jpse) {
1.416 - ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, jpse);
1.417 - }
1.418 -
1.419 -
1.420 - }
1.421 - }
1.422 -
1.423 -
1.424 }
2.1 --- a/visualweb.project.jsfloader/src/org/netbeans/modules/visualweb/project/jsfloader/JsfJspDataNode.java Fri Apr 04 10:20:42 2008 -0700
2.2 +++ b/visualweb.project.jsfloader/src/org/netbeans/modules/visualweb/project/jsfloader/JsfJspDataNode.java Fri Apr 04 17:10:51 2008 -0700
2.3 @@ -122,26 +122,6 @@
2.4 JsfProjectUtils.removeProjectPropertyListener(project, listener);
2.5 }
2.6
2.7 - /**
2.8 - * If this is a portlet project and the page is part of an initial mode,
2.9 - * we need to unset the initial page.
2.10 - * -David Botterill 12/7/2005
2.11 - */
2.12 - FileObject fo = getDataObject().getPrimaryFile();
2.13 - if(null == fo) return;
2.14 - JsfPortletSupport portletSupport = JsfJspDataNode.getPortletSupport(fo);
2.15 - if(null != portletSupport) {
2.16 - try {
2.17 - if(portletSupport.isInitialPage(PortletModeType.VIEW, fo) ||
2.18 - portletSupport.isInitialPage(PortletModeType.EDIT, fo) ||
2.19 - portletSupport.isInitialPage(PortletModeType.HELP, fo)) {
2.20 - portletSupport.unsetInitialPage(fo);
2.21 - }
2.22 - } catch(JsfPortletSupportException pse) {
2.23 - ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, pse);
2.24 - }
2.25 - }
2.26 -
2.27 super.destroy();
2.28 }
2.29