org.eclipse.osee.framework.ui.skynet.ArtifactStructuredSelection.java Source code

Java tutorial

Introduction

Here is the source code for org.eclipse.osee.framework.ui.skynet.ArtifactStructuredSelection.java

Source

/*******************************************************************************
 * Copyright (c) 2011 Boeing.
 * 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:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.ui.skynet;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;

public final class ArtifactStructuredSelection implements IStructuredSelection {

    private final List<Artifact> selectedItems;

    public ArtifactStructuredSelection(Artifact... selectedItems) {
        this(Arrays.asList(selectedItems));
    }

    public ArtifactStructuredSelection(List<Artifact> selectedItems) {
        this.selectedItems = selectedItems;
    }

    @Override
    public boolean isEmpty() {
        return selectedItems.isEmpty();
    }

    @Override
    public Artifact getFirstElement() {
        return isEmpty() ? null : selectedItems.iterator().next();
    }

    @Override
    public Iterator<Artifact> iterator() {
        return selectedItems.iterator();
    }

    @Override
    public int size() {
        return selectedItems.size();
    }

    @Override
    public Object[] toArray() {
        return selectedItems.toArray();
    }

    @Override
    public List<Artifact> toList() {
        return selectedItems;
    }
}