/**
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.bricket.web.common.info;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.util.string.Strings;
import brix.Brix;
import brix.web.BrixRequestCycleProcessor;
import brix.workspace.Workspace;
/**
* @author Ingo Renner
* @author Henning Teek
*/
public class WorkspaceIdPanel extends Panel {
private static final String WORKSPACE_ATTRIBUTE_NAME = "brix:site-name";
public static final String WORKSPACE_ATTRIBUTE_STATE = "brix:site-state";
public WorkspaceIdPanel(String id) {
super(id);
}
@Override
protected void onBeforeRender() {
if (!hasBeenRendered()) {
initGui();
}
super.onBeforeRender();
}
private void initGui() {
add(new Label("workspaceid", getUserVisibleName(Brix.get().getWorkspaceManager()
.getWorkspace(getCurrentWorkspaceId()))));
}
private String getCurrentWorkspaceId() {
return ((BrixRequestCycleProcessor) getRequestCycle().getProcessor()).getWorkspace();
}
private String getUserVisibleName(Workspace workspace) {
String name = "Site - " + getWorkspaceName(workspace);
String state = getWorkspaceState(workspace);
if (!Strings.isEmpty(state)) {
name = name + " - " + state;
}
return name;
}
private String getWorkspaceName(Workspace workspace) {
return workspace.getAttribute(WORKSPACE_ATTRIBUTE_NAME);
}
public String getWorkspaceState(Workspace workspace) {
return workspace.getAttribute(WORKSPACE_ATTRIBUTE_STATE);
}
}