/*
* 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 java.io.File;
import javax.swing.JFrame;
import org.geoforge.guillc.event.GfrEvtPanelChange;
import org.geoforge.guillc.event.GfrEvtValidityChanged;
import org.geoforge.guillc.handler.IGfrHandlerListenerPanelDialog;
import org.geoforge.guillc.handler.IGfrHandlerValidityListener;
import org.geoforge.guillc.panel.GfrPnlSelEdtIoChooserFolderWriter;
import org.geoforge.lang.util.GfrResBundleLang;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
public class GfrDlgAddFolderAbs extends GfrDlgCmdCancelOkExtItmLstUnselectableAbs
implements IGfrHandlerListenerPanelDialog, IGfrHandlerValidityListener
{
protected GfrPnlSelEdtIoChooserFolderWriter _pnlSelectFolderLocation;
protected String _getMessageErrorFolderAlreadyExist()
{
return GfrResBundleLang.s_getInstance().getValue("sentence.alreadyExistingFolder");
}
public GfrDlgAddFolderAbs(
JFrame frmOwner,
String[] strsExistingItems,
String strSentence)
{
super(
frmOwner,
strsExistingItems,
strSentence);
this._pnlSelectFolderLocation = new GfrPnlSelEdtIoChooserFolderWriter(
(IGfrHandlerListenerPanelDialog) this);
this._pnlSelectFolderLocation.addPanelListener((IGfrHandlerListenerPanelDialog) this);
}
@Override
public boolean init()
{
if (!super.init())
return false;
if (!this._pnlSelectFolderLocation.init())
return false;
String strWrkPath = _pnlSelectFolderLocation.getIoFolder()
+ java.io.File.separator
+ _pnlSelectFolderLocation.getIoName();
boolean founded = false;
Integer i = 1;
while (!founded && i < 1000)
{
String strIncrement = i.toString();
File fleWorkspace = new File(strWrkPath + strIncrement);
if (!fleWorkspace.exists())
{
this._pnlSelectFolderLocation.setIoName(
this._pnlSelectFolderLocation.getIoName() + strIncrement);
founded = true;
}
i++;
}
super.setResizable(false);
super._pnlContent.add(this._pnlSelectFolderLocation);
this.pack();
return true;
}
@Override
public void destroy()
{
super.destroy();
if (this._pnlSelectFolderLocation != null)
{
this._pnlSelectFolderLocation.destroy();
this._pnlSelectFolderLocation = null;
}
}
public String getValuePath()
{
return this._pnlSelectFolderLocation.getValuePath();
}
protected boolean _nameHasNoError_()
{
String strName = this._pnlSelectFolderLocation.getIoName();
if (strName == null || strName.length() < 1)
return true;
return _nameEnablesOk();
}
protected boolean _nameEnablesOk()
{
String strName = this._pnlSelectFolderLocation.getIoName();
if (strName == null || strName.length() < 1)
return false;
File fleWorkspace = new File(this._pnlSelectFolderLocation.getValuePath());
if (fleWorkspace.exists())
{
String strError = null;
if (fleWorkspace.isFile())
strError = "File with same name already exists.";
else
strError = _getMessageErrorFolderAlreadyExist();
validityChanged(
new GfrEvtValidityChanged(false,strError));
return false;
}
return true;
}
@Override
protected boolean _okEnableable()
{
return _nameEnablesOk();
}
@Override
protected boolean _noErrorToDisplay()
{
return _nameHasNoError_();
}
@Override
protected void _updateModifiedFieldStatus(GfrEvtPanelChange e)
{
Object obj = e.getSource();
if (obj.equals(this._pnlSelectFolderLocation.getObjectName()))
{
boolean bln = _nameEnablesOk();
this._pnlSelectFolderLocation.setCorrectInput(bln);
return;
}
}
}