Commit 471d6930 authored by Nico Mack's avatar Nico Mack

Initial commit of file

parent 5800d7f6
/**
* Copyright Luxembourg Institute of Science and Technology, 2017. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.widget.corona.bundle;
import lu.list.itis.dkd.dbc.annotation.Nullable;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapCallback;
import lu.list.itis.dkd.tui.bootstrapping.BootstrapContext;
import lu.list.itis.dkd.tui.bootstrapping.BootstrappingUtils;
import lu.list.itis.dkd.tui.bootstrapping.CoronaBootstrapper;
import lu.list.itis.dkd.tui.exception.BuildException;
import lu.list.itis.dkd.tui.utility.Externalization;
import lu.list.itis.dkd.tui.widget.corona.Corona;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.jdom2.Element;
/**
* Provides a way to logically organize and label a set of coronas. Bundles can also be altered
* dynamically, i.e. coronas may be added or removed at runtime.
*
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 2.5.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class CoronaBundle implements Comparable<CoronaBundle> {
private String name;
private boolean exclusive;
private Multimap<Integer, Corona> coronas;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
public CoronaBundle() {
this.name = Externalization.EMPTY_STRING;
this.exclusive = false;
this.coronas = ArrayListMultimap.create();
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public CoronaBundle(Element rootElement) throws BuildException {
this.buildFromBootstrap(rootElement, null, null);
}
// ---------------------------------------------------------------------------
/**
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
public CoronaBundle(Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
this.buildFromBootstrap(rootElement, context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitive(s)
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
* @param rootElement
* @param context
* @param callback
* @throws BuildException
*/
// ---------------------------------------------------------------------------
private void buildFromBootstrap(@Nullable Element rootElement, BootstrapContext context, BootstrapCallback callback) throws BuildException {
name = BootstrappingUtils.getAttributeAsString(rootElement, Externalization.NAME_NODE, BootstrappingUtils.OPTIONAL, Externalization.EMPTY_STRING);
exclusive = BootstrappingUtils.getContentAsBoolean(rootElement, Externalization.EXCLUSIVE_NODE, BootstrappingUtils.OPTIONAL, Boolean.FALSE, context);
coronas = CoronaBootstrapper.getCoronas(rootElement.getChild(Externalization.CORONAS_NODE), context, callback);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Simple getter method for name.
*
* @return The value of name.
*/
// ---------------------------------------------------------------------------
public String getName() {
return name;
}
// ---------------------------------------------------------------------------
/**
* Simple setter method for name.
*
* @param name
* The value to set name to.
*/
// ---------------------------------------------------------------------------
public void setName(String name) {
this.name = name;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for exclusive.
*
* @return The value of exclusive.
*/
// ---------------------------------------------------------------------------
public boolean isExclusive() {
return exclusive;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for coronas.
*
* @return The value of coronas.
*/
// ---------------------------------------------------------------------------
public Multimap<Integer, Corona> getCoronas() {
return coronas;
}
// ---------------------------------------------------------------------------
/**
* Adds the specified corona to this bundle unless it is already contained in the bundle
*
* @param handleId
*
* @param corona
* specifies the corona to add to this bundle
* @return <code>true</code> if the specified corona was added to the bundle and the bundle changed
* as a consequence, <code>false</code> otherwise.
*/
// ---------------------------------------------------------------------------
public boolean addCorona(int handleId, Corona corona) {
boolean added = false;
if (!coronas.containsEntry(handleId, corona)) {
added = coronas.put(handleId, corona);
}
return added;
}
// ---------------------------------------------------------------------------
/**
* Attempts to remove the specified corona from this bundle.
*
* @param handleId
*
* @param corona
* specifies the corona to be removed
* @return <code>true</code> if specified corona was part of this bundle and was successfully
* removed, <code>false</code> otherwise.
*/
// ---------------------------------------------------------------------------
public boolean removeCorona(int handleId, Corona corona) {
boolean removed = false;
if (coronas.containsEntry(handleId, corona)) {
removed = coronas.remove(handleId, corona);
}
return removed;
}
// ---------------------------------------------------------------------------
/** {@inheritDoc} */
// ---------------------------------------------------------------------------
@Override
public int compareTo(CoronaBundle bundle) {
if (bundle == null)
throw new NullPointerException();
return name.compareTo(bundle.name);
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment