/*
* Copyright (C) 2011-2014 GeoForge Project
*
* This program 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, 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.geoforge.guillc.dialog;
import javax.swing.JFrame;
import org.geoforge.guillc.event.GfrEvtPanelChange;
import org.geoforge.guillc.event.GfrEvtValidityChanged;
import org.geoforge.guillc.panel.GfrPnl;
import org.geoforge.guillc.panel.GfrPnlGrpAbs;
import org.geoforge.guillc.panel.GfrPnlGrpTxfFxdEditableYes;
import org.geoforge.guillc.handler.IGfrHandlerListenerPanelDialog;
import org.geoforge.lang.util.GfrResBundleLang;
import org.geoforge.java.lang.string.GfrUtlString;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
public abstract class GfrDlgIoVarImpXloAbs extends GfrDlgIoVarImpAbs
{
public String getNameTarget()
{
return this._pnlNameTarget_.getValue();
}
private String _strWhat_ = null;
private GfrPnlGrpTxfFxdEditableYes _pnlNameTarget_;
//--
//--beg private methods
private boolean _nameHasNoError_()
{
String strName = this._pnlNameTarget_.getValue();
if (strName == null || strName.length() < 1)
return true;
return _nameEnablesOk_();
}
private boolean _nameEnablesOk_()
{
String strName = this._pnlNameTarget_.getValue();
if (strName == null || strName.length() < 1)
{
return false;
}
if (super._alreadyExists(strName))
{
validityChanged(new GfrEvtValidityChanged(false, "Name already exists"));
return false;
}
return true;
}
//--end private methods
//--
//--
//--beg protected methods
@Override
protected boolean _okEnableable()
{
return super._okEnableable()&&_nameEnablesOk_();
}
@Override
protected boolean _noErrorToDisplay()
{
return _nameHasNoError_();
}
@Override
protected void _updateModifiedFieldStatus(GfrEvtPanelChange e)
{
Object objSource = e.getSource();
if (objSource.equals(_pnlNameTarget_))
{
boolean bln = _nameEnablesOk_();
((GfrPnlGrpAbs) objSource).setValueIsOk(bln);
return;
}
super._updateModifiedFieldStatus(e);
}
protected GfrDlgIoVarImpXloAbs(
JFrame frmOwner,
String[] strsExistingItems,
String strSentence,
String strWhat)
{
super(
frmOwner,
strsExistingItems,
strSentence);
this._pnlNameTarget_ = new GfrPnlGrpTxfFxdEditableYes(
GfrResBundleLang.s_getInstance().getValue("word.name"));
super.addToListResizable(this._pnlNameTarget_);
this._pnlNameTarget_.setWidth(120);
this._pnlNameTarget_.addPanelListener((IGfrHandlerListenerPanelDialog) this);
this._strWhat_ = strWhat;
}
//--end protected methods
//--
//--
//--beg public methods
@Override
public boolean init()
{
if (!super.init())
return false;
if (!this._pnlNameTarget_.init())
return false;
this._pnlNameTarget_.setMandatoryIcon(true);
super._pnlContent.addWithSpace((GfrPnl) this._pnlNameTarget_);
super._pnlIoChooser.addPanelListener((IGfrHandlerListenerPanelDialog) this);
this._pnlNameTarget_.setContent(
GfrUtlString.s_createUniqueNameByNumber(super.getExistingsItems(), this._strWhat_));
this._pnlNameTarget_.selectText();
return true;
}
@Override
public void destroy()
{
super.destroy();
if (this._pnlNameTarget_ != null)
{
this._pnlNameTarget_.destroy();
this._pnlNameTarget_ = null;
}
}
public String getObjectName()
{
return this._pnlNameTarget_.getValue();
}
//--end public methods
//--
}