Java tutorial
/** * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at license/ESCIDOC.LICENSE * or https://www.escidoc.org/license/ESCIDOC.LICENSE . * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at license/ESCIDOC.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * * Copyright 2012 Fachinformationszentrum Karlsruhe Gesellschaft * fuer wissenschaftlich-technische Information mbH and Max-Planck- * Gesellschaft zur Foerderung der Wissenschaft e.V. * All rights reserved. Use is subject to license terms. */ package org.escidoc.browser.controller; import org.escidoc.browser.model.ResourceProxy; import org.escidoc.browser.ui.ViewConstants; import org.escidoc.browser.ui.maincontent.View; import org.escidoc.browser.ui.view.helpers.BreadCrumbMenu; import com.google.common.base.Preconditions; import com.vaadin.ui.AbstractComponentContainer; import com.vaadin.ui.Component; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.Panel; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.themes.Runo; @SuppressWarnings("serial") public class ContentModelView extends View { private final ResourceProxy resourceProxy; private Panel breadCrump; public ContentModelView(ResourceProxy rp) { Preconditions.checkNotNull(rp, "rp is null: %s", rp); this.resourceProxy = rp; } public void buildContentPanel() { this.setImmediate(false); this.setWidth("100.0%"); this.setHeight("100.0%"); this.setStyleName(Runo.PANEL_LIGHT); // vlContentPanel assign a layout to this panel this.setContent(buildVlContentPanel()); } private VerticalLayout buildVlContentPanel() { // common part: create layout VerticalLayout vlContentPanel = new VerticalLayout(); vlContentPanel.setImmediate(false); vlContentPanel.setWidth("100.0%"); vlContentPanel.setHeight("100.0%"); vlContentPanel.setMargin(false, true, false, true); // breadCrumpPanel breadCrump = buildBreadCrumpPanel(); vlContentPanel.addComponent(breadCrump); // resourcePropertiesPanel Panel resourcePropertiesPanel = buildResourcePropertiesPanel(); vlContentPanel.addComponent(resourcePropertiesPanel); vlContentPanel.setExpandRatio(resourcePropertiesPanel, 1.5f); // metaViewsPanel contains Panel for the DirectMembers & for the Metas Panel metaViewsPanel = buildMetaViewsPanel(); vlContentPanel.addComponent(metaViewsPanel); vlContentPanel.setExpandRatio(metaViewsPanel, 8.0f); return vlContentPanel; } private Panel buildMetaViewsPanel() { // common part: create layout Panel metaViewsPanel = new Panel(); metaViewsPanel.setImmediate(false); metaViewsPanel.setWidth("100.0%"); metaViewsPanel.setHeight("100.0%"); metaViewsPanel.setStyleName(Runo.PANEL_LIGHT); // hlMetaViews HorizontalLayout hlMetaViews = buildHlMetaViews(); metaViewsPanel.setContent(hlMetaViews); return metaViewsPanel; } private HorizontalLayout buildHlMetaViews() { // common part: create layout HorizontalLayout hlMetaViews = new HorizontalLayout(); hlMetaViews.setImmediate(false); hlMetaViews.setWidth("100.0%"); hlMetaViews.setHeight("100.0%"); hlMetaViews.setMargin(false); // leftPanel Panel leftPanel = buildLeftPanel(); hlMetaViews.addComponent(leftPanel); hlMetaViews.setExpandRatio(leftPanel, 4.5f); // rightPanel Panel rightPanel = buildRightPanel(); hlMetaViews.addComponent(rightPanel); hlMetaViews.setExpandRatio(rightPanel, 5.5f); return hlMetaViews; } private Panel buildLeftPanel() { // common part: create layout Panel leftPanel = new Panel(); leftPanel.setImmediate(false); leftPanel.setWidth("100.0%"); leftPanel.setHeight("100.0%"); // vlLeftPanel VerticalLayout vlLeftPanel = buildVlLeftPanel(); leftPanel.setContent(vlLeftPanel); return leftPanel; } private VerticalLayout buildVlLeftPanel() { // common part: create layout VerticalLayout vlLeftPanel = new VerticalLayout(); vlLeftPanel.setImmediate(false); vlLeftPanel.setWidth("100.0%"); vlLeftPanel.setHeight("100.0%"); vlLeftPanel.setMargin(false); // directMembersPanel Panel directMembersPanel = buildDirectMembersPanel(); directMembersPanel.setStyleName("directmembers"); vlLeftPanel.addComponent(directMembersPanel); return vlLeftPanel; } private Panel buildDirectMembersPanel() { // common part: create layout Panel directMembersPanel = new Panel(); directMembersPanel.setImmediate(false); directMembersPanel.setWidth("100.0%"); directMembersPanel.setHeight("100.0%"); directMembersPanel.setStyleName(Runo.PANEL_LIGHT); // vlDirectMember VerticalLayout vlDirectMember = new VerticalLayout(); vlDirectMember.setImmediate(false); vlDirectMember.setWidth("100.0%"); vlDirectMember.setHeight("100.0%"); vlDirectMember.setMargin(false); directMembersPanel.setContent(vlDirectMember); return directMembersPanel; } private Panel buildRightPanel() { // common part: create layout Panel rightPanel = new Panel(); rightPanel.setImmediate(false); rightPanel.setWidth("100.0%"); rightPanel.setHeight("100.0%"); // vlRightPanel VerticalLayout vlRightPanel = buildVlRightPanel(); rightPanel.setContent(vlRightPanel); return rightPanel; } private VerticalLayout buildVlRightPanel() { // common part: create layout VerticalLayout vlRightPanel = new VerticalLayout(); vlRightPanel.setImmediate(false); vlRightPanel.setWidth("100.0%"); vlRightPanel.setHeight("100.0%"); vlRightPanel.setMargin(false); return vlRightPanel; } private Panel buildResourcePropertiesPanel() { // common part: create layout Panel resourcePropertiesPanel = new Panel(); resourcePropertiesPanel.setImmediate(false); resourcePropertiesPanel.setWidth("100.0%"); resourcePropertiesPanel.setHeight("100%"); resourcePropertiesPanel.setStyleName(Runo.PANEL_LIGHT); // vlResourceProperties resourcePropertiesPanel.setContent(buildVlResourceProperties()); return resourcePropertiesPanel; } private Panel buildBreadCrumpPanel() { // common part: create layout Panel breadCrumpPanel = new Panel(); breadCrumpPanel.setImmediate(false); breadCrumpPanel.setWidth("100.0%"); breadCrumpPanel.setHeight("30px"); breadCrumpPanel.setStyleName(Runo.PANEL_LIGHT); // vlBreadCrump VerticalLayout vlBreadCrump = new VerticalLayout(); vlBreadCrump.setImmediate(false); vlBreadCrump.setWidth("100.0%"); vlBreadCrump.setHeight("100.0%"); vlBreadCrump.setMargin(false); breadCrumpPanel.setContent(vlBreadCrump); // BreadCreumb new BreadCrumbMenu(breadCrumpPanel, resourceProxy.getName().toString()); return breadCrumpPanel; } private VerticalLayout buildVlResourceProperties() { // common part: create layout VerticalLayout vlResourceProperties = new VerticalLayout(); vlResourceProperties.setImmediate(false); vlResourceProperties.setWidth("100.0%"); vlResourceProperties.setHeight("100.0%"); vlResourceProperties.setMargin(false); // creating the properties / without the breadcrump createProperties(vlResourceProperties); return vlResourceProperties; } private void createProperties(VerticalLayout vlResourceProperties) { // Create Property fields. Probably not the best place for them to be vlResourceProperties.addComponent(bindNameToHeader()); vlResourceProperties.addComponent(bindDescriptionToHeader()); addHorizontalRuler(vlResourceProperties); vlResourceProperties.addComponent(bindProperties()); } private Component bindDescriptionToHeader() { VerticalLayout l = new VerticalLayout(); l.setMargin(false); l.setWidth("100%"); l.addComponent(new Label(ViewConstants.DESCRIPTION_LBL + resourceProxy.getDescription())); return l; } private VerticalLayout bindNameToHeader() { VerticalLayout headerLayout = new VerticalLayout(); headerLayout.setMargin(false); headerLayout.setWidth("100%"); final Label headerContext = new Label("Content Model: " + resourceProxy.getName()); headerContext.setStyleName("h1 fullwidth"); headerContext.setDescription("Content Model"); headerLayout.addComponent(headerContext); return headerLayout; } private HorizontalLayout bindProperties() { HorizontalLayout hlProperties = new HorizontalLayout(); hlProperties.setWidth("100%"); VerticalLayout vlLeft = new VerticalLayout(); VerticalLayout vlRight = new VerticalLayout(); final Label descMetadata1 = new Label("ID: " + resourceProxy.getId()); vlLeft.addComponent(descMetadata1); // RIGHT SIDE final Label descMetadata2 = new Label(ViewConstants.CREATED_BY + " " + resourceProxy.getCreator() + " on " + resourceProxy.getCreatedOn() + "<br/>", Label.CONTENT_XHTML); descMetadata2.setStyleName("floatright columnheight50"); descMetadata2.setWidth("65%"); vlRight.addComponent(descMetadata2); hlProperties.addComponent(vlLeft); hlProperties.setExpandRatio(vlLeft, 0.4f); hlProperties.addComponent(vlRight); hlProperties.setExpandRatio(vlRight, 0.6f); return hlProperties; } private static void addHorizontalRuler(AbstractComponentContainer contentLayout) { final Label descRuler = new Label("<hr />", Label.CONTENT_RAW); descRuler.setStyleName("hr"); contentLayout.addComponent(descRuler); } public void refreshView() { // not yet implemented. } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((resourceProxy == null) ? 0 : resourceProxy.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } ContentModelView other = (ContentModelView) obj; if (resourceProxy == null) { if (other.resourceProxy != null) { return false; } } else if (!resourceProxy.equals(other.resourceProxy)) { return false; } return true; } }