001/* 002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others. 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 * 016 * Contributors: 017 * troger 018 */ 019package org.nuxeo.ecm.platform.annotations.gwt.client.view.decorator; 020 021import org.nuxeo.ecm.platform.annotations.gwt.client.AnnotationConstant; 022import org.nuxeo.ecm.platform.annotations.gwt.client.controler.AnnotationController; 023import org.nuxeo.ecm.platform.annotations.gwt.client.model.Annotation; 024 025import com.google.gwt.dom.client.Document; 026import com.google.gwt.dom.client.Element; 027import com.google.gwt.dom.client.Node; 028import com.google.gwt.dom.client.SpanElement; 029 030/** 031 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 032 */ 033public class NuxeoSelectedTextDecoratorVisitor extends NuxeoDecoratorVisitor { 034 035 public NuxeoSelectedTextDecoratorVisitor(Annotation annotation, AnnotationController controller) { 036 super(annotation, controller); 037 } 038 039 @Override 040 protected Element decorateTextWithSpan(String data) { 041 if (data.trim().length() == 0) { 042 // don't add span to empty text 043 return null; 044 } 045 046 Document document = currentNode.getOwnerDocument(); 047 SpanElement spanElement = getSpanElement(document); 048 spanElement.setInnerText(data); 049 Node parent = currentNode.getParentNode(); 050 String className = AnnotationConstant.SELECTED_TEXT_CLASS_NAME; 051 if (parent.getNodeName().equalsIgnoreCase("span")) { 052 String parentClassName = ((SpanElement) parent.cast()).getClassName(); 053 if (parentClassName.indexOf(AnnotationConstant.SELECTED_TEXT_CLASS_NAME) != -1) { 054 className = parentClassName + AnnotationConstant.SELECTED_TEXT_CLASS_NAME; 055 } 056 } 057 spanElement.setClassName(className); 058 insertBefore(parent, currentNode.getNextSibling(), spanElement); 059 return spanElement; 060 } 061 062 @Override 063 protected SpanElement getSpanElement(Document document) { 064 SpanElement spanElement = document.createSpanElement(); 065 return spanElement; 066 } 067 068}