All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fosstrak.llrp.commander.dialogs.AddReaderDialog Maven / Gradle / Ivy

/*
 *  
 *  Fosstrak LLRP Commander (www.fosstrak.org)
 * 
 *  Copyright (C) 2008 ETH Zurich
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see  
 *
 */

package org.fosstrak.llrp.commander.dialogs;

import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.fosstrak.llrp.adaptor.AdaptorManagement;

/**
 * dialog to add a new reader to the reader explorer.
 * @author sawielan
 *
 */
public class AddReaderDialog extends ConnectDialog {
	
	/** the index for the reader name in the values array. */
	private static final int VALUE_READER_NAME = 0;
	
	/** the index for the reader ip in the values array. */
	private static final int VALUE_READER_IP = 1;
	
	/** the index for the reader port in the values array. */
	private static final int VALUE_READER_PORT = 2;
	
	/** increasing number added automatically to the reader name. */
	private static long num = 0;
	
	/** flag whether client initiated or not. */
	private boolean ci = true;
	
	/** handle to the client initiated connection button. */
	protected Button cICon;
	
	/** flag whether connect immediately or not. */
	private boolean connectImmediate = true;
	
	/** handle to the connect immediately button. */
	protected Button conImmed;
	
	/**
	 * create a new add reader dialog.
	 * @param aShell the parent shell.
	 */
	public AddReaderDialog(Shell aShell) {
		super(aShell, "Add Local Reader");
		FIELDS = new String[] { "Reader Name", "IP", "Port" };
		
		// make sure, we propose a unique reader name
		String readerName = String.format("ReaderName%d", num++);
		try {
			while (AdaptorManagement.getInstance().getAdaptor(
					AdaptorManagement.DEFAULT_ADAPTOR_NAME).containsReader(
							readerName)) {
				
				readerName = String.format("ReaderName%d", num++);
			}
		} catch (Exception e) {
			readerName = String.format("ReaderName%d", 
					System.currentTimeMillis());
		}
		DEFAULTS = new String [] { 	readerName, "127.0.0.1", "5084" };
	}
	
	@Override
	protected void addOKButton(Composite parent) {
		final Button btnOK = new Button(parent, SWT.PUSH);
		btnOK.setText("OK");
		btnOK.setLayoutData(gridLabel);
		
		btnOK.addSelectionListener(new SelectionAdapter() {
		      public void widgetSelected(SelectionEvent e) {
		    	  for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy