001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.web.client;
017
018import com.google.gwt.user.client.Window;
019import com.smartgwt.client.types.VerticalAlignment;
020import com.smartgwt.client.widgets.Img;
021import com.smartgwt.client.widgets.Label;
022import com.smartgwt.client.widgets.events.ClickEvent;
023import com.smartgwt.client.widgets.events.ClickHandler;
024import com.smartgwt.client.widgets.form.DynamicForm;
025import com.smartgwt.client.widgets.form.fields.TextItem;
026import com.smartgwt.client.widgets.layout.HLayout;
027import com.smartgwt.client.widgets.layout.VLayout;
028import com.smartgwt.client.widgets.toolbar.ToolStrip;
029import com.smartgwt.client.widgets.toolbar.ToolStripButton;
030import java.util.Collection;
031import org.modeshape.web.shared.BaseCallback;
032import org.modeshape.web.shared.RepositoryName;
033
034/**
035 *
036 * @author kulikov
037 */
038public class Header extends HLayout {
039    
040    private Label userName = new Label();
041
042    public Header(final Console console) {
043        setHeight(50);
044        setWidth100();
045        
046        Img logo = new Img();
047        logo.setSrc("icons/logo.png");
048        
049        logo.setHeight(30);
050        logo.setWidth(190);
051        logo.setValign(VerticalAlignment.CENTER);
052        
053        
054        ToolStrip strip = new ToolStrip();
055        strip.setHeight(50);
056        strip.setWidth100();
057        
058        strip.addSpacer(90);
059        strip.addMember(logo);
060        strip.addSpacer(10);
061        strip.addSeparator();
062        
063        strip.addFill();
064        
065        
066        VLayout p = new VLayout();
067        p.setAlign(VerticalAlignment.CENTER);
068        DynamicForm form = new DynamicForm();
069        
070        p.addMember(form);
071        p.setWidth(300);
072        
073        final TextItem search = new TextItem();
074        search.setTitle("Search");
075        search.setWidth(300);
076        search.setValue("");
077        search.setTop(30);
078        
079        form.setItems(search);
080        
081        strip.setAlign(VerticalAlignment.CENTER);
082        strip.addMember(p);
083       
084        ToolStripButton go = new ToolStripButton();
085        go.setTitle("Go");
086        go.addClickHandler(new ClickHandler() {
087            @Override
088            public void onClick(ClickEvent event) {
089                console.jcrService().findRepositories(search.getValueAsString(), new BaseCallback<Collection<RepositoryName>>() {
090                    @Override
091                    public void onSuccess(Collection<RepositoryName> result) {
092                        console.showRepositories(result);
093                    }
094                });
095            }
096        });
097        
098        strip.addButton(go);
099        
100        userName.setContents("okulikov");
101        userName.setIcon("icons/bullet_blue.png");
102        
103        strip.addSpacer(140);
104        strip.addSeparator();
105        
106        strip.addMember(userName);
107        strip.addSeparator();
108
109        ToolStripButton logout = new ToolStripButton();
110        logout.setTitle("Log out");
111        logout.addClickHandler(new ClickHandler() {
112            @Override
113            public void onClick(ClickEvent event) {
114                console.jcrService().logout(new BaseCallback<String>() {
115                    @Override
116                    public void onSuccess(String result) {
117                        console.changeUserName(null);
118                        Window.Location.replace(result);
119                    }
120                });
121            }
122        });
123        
124        strip.addButton(logout);
125        
126        addMember(strip);
127        setBackgroundColor("#d3d3d3");
128        
129    }
130    
131    public void setUserName(String userName) {
132        if (userName != null && userName.length() > 0) {
133            this.userName.setContents(userName);
134        } else {
135            this.userName.setContents("anonymous");
136        }
137    }
138    
139}