001 // Copyright 2004, 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry.contrib.inspector;
016
017 import org.apache.tapestry.BaseComponent;
018 import org.apache.tapestry.IAsset;
019 import org.apache.tapestry.IRequestCycle;
020
021 /**
022 * Component of the {@link Inspector} page used to select the view.
023 *
024 * @author Howard Lewis Ship
025 */
026
027 public abstract class ViewTabs extends BaseComponent
028 {
029 private static String[] _views =
030 { View.SPECIFICATION, View.TEMPLATE, View.PROPERTIES, View.ENGINE };
031
032 public String[] getViews()
033 {
034 return _views;
035 }
036
037 public abstract void setView(String value);
038
039 public abstract String getView();
040
041 private IAsset getImageForView(boolean focus)
042 {
043 Inspector inspector = (Inspector) getPage();
044
045 String view = getView();
046
047 boolean selected = view.equals(inspector.getView());
048
049 StringBuffer buffer = new StringBuffer(view);
050
051 if (selected)
052 buffer.append("_selected");
053
054 if (focus)
055 buffer.append("_focus");
056
057 String key = buffer.toString();
058
059 return (IAsset) getAssets().get(key);
060 }
061
062 public IAsset getViewImage()
063 {
064 return getImageForView(false);
065 }
066
067 public IAsset getFocusImage()
068 {
069 return getImageForView(true);
070 }
071
072 public IAsset getBannerImage()
073 {
074 Inspector inspector = (Inspector) getPage();
075 String selectedView = inspector.getView();
076 String key = selectedView + "_banner";
077
078 return (IAsset) getAssets().get(key);
079 }
080
081 public void selectTab(IRequestCycle cycle)
082 {
083 Inspector inspector = (Inspector) getPage();
084 inspector.setView(getView());
085 }
086 }