001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package pt.ua.dicoogle.rGUI.server.controllers;
020
021import pt.ua.dicoogle.rGUI.interfaces.controllers.IQRServers;
022import java.util.ArrayList;
023import java.util.concurrent.Semaphore;
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026import org.slf4j.Logger;
027import org.slf4j.LoggerFactory;
028import pt.ua.dicoogle.sdk.datastructs.MoveDestination;
029import pt.ua.dicoogle.core.ServerSettings;
030
031/**
032 * Controller of Query/Retrieve Servers Settings
033 *
034 * @author Samuel Campos <samuelcampos@ua.pt>
035 */
036@Deprecated
037public class QRServers implements IQRServers {
038
039    private ServerSettings settings = null;
040
041    private static Semaphore sem = new Semaphore(1, true);
042    private static QRServers instance = null;
043
044
045    private ArrayList<MoveDestination> moves;
046    
047    public static synchronized QRServers getInstance()
048    {
049        try {
050            sem.acquire();
051            if (instance == null) {
052                instance = new QRServers();
053            }
054            sem.release();
055        } catch (InterruptedException ex) {
056            LoggerFactory.getLogger(QRServers.class).error(ex.getMessage(), ex);
057        }
058        return instance;
059    }
060
061    private QRServers(){
062        settings = ServerSettings.getInstance();
063
064        loadSettings();
065    }
066
067    public void loadSettings(){
068        moves = new ArrayList<MoveDestination>();
069        
070        moves.addAll(settings.getMoves());
071    }
072
073
074    /**
075     * Save the settings related to Startup Services
076     *
077     * not write the settings in XML
078     */
079    public void saveSettings(){
080        settings.setMoves(moves);
081    }
082
083    /**
084     *
085     * @return  true - if there are unsaved settings ( != ServerSettings)
086     *          false - not
087     */
088    public boolean unsavedSettings(){
089        if(!moves.equals(settings.getMoves()))
090            return true;
091
092        return false;
093    }
094
095    /**
096     * Add one Query/Retrieve Server to the list
097     *
098     * @param move
099     * @return
100     */
101    @Override
102    public boolean AddEntry(MoveDestination move){
103
104        if(!moves.contains(move))
105        {
106            moves.add(move);
107            return true;
108        }
109
110        return false;
111    }
112
113    @Override
114    public boolean RemoveEntry(MoveDestination move){
115        return moves.remove(move);
116    }
117
118    @Override
119    public ArrayList<MoveDestination> getMoves(){
120        return moves;
121    }
122}