diff options
Diffstat (limited to 'org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java')
-rw-r--r-- | org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java new file mode 100644 index 00000000..735755c8 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * @author Eugene Kuleshov + */ +public class ListEditorContentProvider<T> implements IStructuredContentProvider { + + public static final Object[] EMPTY = new Object[0]; + private boolean shouldSort; + private Comparator<T> comparator; + + @SuppressWarnings("unchecked") + public Object[] getElements(Object input) { + if(input instanceof List) { + List<T> list = (List<T>) input; + if (shouldSort) { + T[] array = (T[]) list.toArray(); + Arrays.<T>sort(array, comparator); + return array; + } + return list.toArray(); + } + return EMPTY; + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + public void setShouldSort(boolean shouldSort) { + this.shouldSort = shouldSort; + } + + public void setComparator(Comparator<T> comparator) { + this.comparator = comparator; + } +} |