001/*
002 * (C) Copyright 2006-2016 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 *     Tiago Cardoso <tcardoso@nuxeo.com>
018 */
019package org.nuxeo.ecm.platform.threed.service;
020
021import org.nuxeo.common.xmap.annotation.XNode;
022import org.nuxeo.common.xmap.annotation.XObject;
023
024import static java.lang.Math.abs;
025
026/**
027 * Object representing an automatic render view on the {@link ThreeDService}. An {@code AutomaticRenderView} references
028 * the {@code RenderView} through its name.
029 *
030 * @since 8.4
031 */
032@XObject("automaticRenderView")
033public class AutomaticRenderView implements Comparable<AutomaticRenderView> {
034
035    @XNode("@order")
036    protected Integer order;
037
038    @XNode("@name")
039    protected String name;
040
041    @XNode("@enabled")
042    protected Boolean enabled;
043
044    public AutomaticRenderView(AutomaticRenderView other) {
045        order = other.order;
046        name = other.name;
047        enabled = other.enabled;
048    }
049
050    public AutomaticRenderView() {
051        super();
052    }
053
054    public Integer getOrder() {
055        return order;
056    }
057
058    public void setOrder(Integer order) {
059        this.order = order;
060    }
061
062    public String getName() {
063        return name;
064    }
065
066    public void setName(String name) {
067        this.name = name;
068    }
069
070    public String getId() {
071        return String.valueOf(abs(name.hashCode()));
072    }
073
074    public boolean isEnabled() {
075        return (enabled == null) || enabled;
076    }
077
078    public void setEnabled(boolean enabled) {
079        this.enabled = enabled;
080    }
081
082    @Override
083    public int compareTo(AutomaticRenderView o) {
084        return name.compareTo(o.name);
085    }
086
087    public void merge(AutomaticRenderView src) {
088        if (src.order != null) {
089            order = src.order;
090        }
091        if (src.name != null) {
092            name = src.name;
093        }
094        if (src.enabled != null) {
095            enabled = src.enabled;
096        }
097    }
098}