001/* 002 * (C) Copyright 2010 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 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.platform.forms.layout.api.impl; 020 021import java.util.Comparator; 022import java.util.List; 023 024import org.nuxeo.ecm.platform.forms.layout.api.LayoutRow; 025 026/** 027 * Compares selected row instances to order them in the same order that given by the input list of row names. 028 * 029 * @author Anahide Tchertchian 030 */ 031public class LayoutRowComparator implements Comparator<LayoutRow> { 032 033 protected List<String> rowNames; 034 035 public LayoutRowComparator(List<String> rowNames) { 036 super(); 037 this.rowNames = rowNames; 038 } 039 040 @Override 041 public int compare(LayoutRow o1, LayoutRow o2) { 042 if (rowNames == null) { 043 return 0; 044 } 045 Integer index1 = Integer.valueOf(rowNames.indexOf(o1.getName())); 046 Integer index2 = Integer.valueOf(rowNames.indexOf(o2.getName())); 047 return index1.compareTo(index2); 048 } 049}