use of pcgen.facade.core.UIDelegate in project pcgen by PCGen.
the class FtlMigrationTest method loadCharacter.
/**
* @param characterFile
* @return
*/
private CharacterFacade loadCharacter(String characterFilename) {
File file = new File(characterFilename);
if (!PCGFile.isPCGenCharacterFile(file)) {
Logging.errorPrint("Invalid character file specified: " + file.getAbsolutePath());
return null;
}
// Load data
UIDelegate uiDelegate = new ConsoleUIDelegate();
SourceSelectionFacade sourcesForCharacter = CharacterManager.getRequiredSourcesForCharacter(file, uiDelegate);
Logging.log(Logging.INFO, "Loading sources " + sourcesForCharacter.getCampaigns() + " using game mode " + sourcesForCharacter.getGameMode());
SourceFileLoader loader = new SourceFileLoader(sourcesForCharacter, uiDelegate);
loader.execute();
// Load character
CharacterFacade character = CharacterManager.openCharacter(file, uiDelegate, loader.getDataSetFacade());
return character;
}
use of pcgen.facade.core.UIDelegate in project pcgen by PCGen.
the class Main method startupWithoutGUI.
private static boolean startupWithoutGUI() {
loadProperties(false);
validateEnvironment(false);
PCGenTaskExecutor executor = new PCGenTaskExecutor();
executor.addPCGenTask(createLoadPluginTask());
executor.addPCGenTask(new GameModeFileLoader());
executor.addPCGenTask(new CampaignFileLoader());
executor.execute();
UIDelegate uiDelegate = new ConsoleUIDelegate();
BatchExporter exporter = new BatchExporter(exportSheet, uiDelegate);
boolean result = true;
if (partyFile != null) {
result = exporter.exportParty(partyFile, outputFile);
}
if (characterFile != null) {
result = exporter.exportCharacter(characterFile, outputFile);
}
return result;
}
use of pcgen.facade.core.UIDelegate in project pcgen by PCGen.
the class CharacterManager method saveCharacter.
/**
* Saves this character to the character's file specified
* by character.getFileRef().getReference()
* This is expected to be called before a character is to
* be removed from the list of open characters.
* @param character the character to be saved
* @return true if the save succeeded, false if not
*/
public static boolean saveCharacter(CharacterFacade character) {
File file = character.getFileRef().get();
if (StringUtils.isBlank(file.getName())) {
return false;
}
Logging.log(Logging.INFO, //$NON-NLS-1$
"Saving character " + character.getNameRef().get() + " - " + //$NON-NLS-1$
file.getAbsolutePath());
if (character instanceof CharacterFacadeImpl) {
UIDelegate delegate = character.getUIDelegate();
try {
((CharacterFacadeImpl) character).save();
} catch (final NullPointerException e) {
Logging.errorPrint("Could not save " + character.getNameRef().get(), e);
delegate.showErrorMessage(Constants.APPLICATION_NAME, "Could not save " + character.getNameRef().get());
return false;
} catch (final IOException e) {
Logging.errorPrint("Could not save " + character.getNameRef().get(), e);
delegate.showErrorMessage(Constants.APPLICATION_NAME, "Could not save " + character.getNameRef().get() + " due to the error:\n" + e.getMessage());
return false;
}
} else {
Logging.errorPrint("Could not save " + character.getNameRef().get() + " due to unexpected class of character: " + character.getClass().getCanonicalName());
return false;
}
recentCharacters.addRecentFile(file);
return true;
}
use of pcgen.facade.core.UIDelegate in project pcgen by PCGen.
the class DataLoadTest method testLoadSources.
/**
* Test the load of the current source. This will check for any load errors or warnings but ignores deprecation warnings.
*/
@Test
public void testLoadSources() {
UIDelegate uiDelegate = new MockUIDelegate();
SourceFileLoader loader = new SourceFileLoader(sourceSelection, uiDelegate);
errors = new ArrayList<>();
loader.addPCGenTaskListener(this);
loader.execute();
List<String> errorList = new ArrayList<>();
List<String> warningList = new ArrayList<>();
for (LogRecord logRecord : errors) {
if (logRecord.getLevel().intValue() > Logging.WARNING.intValue()) {
errorList.add(logRecord.getMessage());
} else if (logRecord.getLevel().intValue() > Logging.INFO.intValue()) {
warningList.add(logRecord.getMessage());
}
}
assertEquals("Errors encountered while loading " + sourceSelection, "", StringUtils.join(errorList, ",\n"));
assertEquals("Warnings encountered while loading " + sourceSelection, "", StringUtils.join(errorList, ",\n"));
}
use of pcgen.facade.core.UIDelegate in project pcgen by PCGen.
the class PCGenFrame method showSaveCharacterChooser.
/**
* This brings up a file chooser allows the user to select
* the location that a character should be saved to.
* @param character the character to be saved
*/
boolean showSaveCharacterChooser(CharacterFacade character) {
PCGenSettings context = PCGenSettings.getInstance();
String parentPath = lastCharacterPath;
if (parentPath == null) {
parentPath = context.getProperty(PCGenSettings.PCG_SAVE_PATH);
}
chooser.setCurrentDirectory(new File(parentPath));
File file = character.getFileRef().get();
File prevFile = file;
if (file == null || StringUtils.isEmpty(file.getName())) {
file = new File(parentPath, character.getNameRef().get() + Constants.EXTENSION_CHARACTER_FILE);
}
chooser.setSelectedFile(file);
chooser.resetChoosableFileFilters();
FileFilter filter = new FileNameExtensionFilter("Pcg files only", "pcg");
chooser.addChoosableFileFilter(filter);
chooser.setFileFilter(filter);
int ret = chooser.showSaveDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
if (!file.getName().endsWith(Constants.EXTENSION_CHARACTER_FILE)) {
file = new File(file.getParent(), file.getName() + Constants.EXTENSION_CHARACTER_FILE);
}
UIDelegate delegate = character.getUIDelegate();
if (file.isDirectory()) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
LanguageBundle.getString("in_savePcDirOverwrite"));
return showSaveCharacterChooser(character);
}
if (file.exists() && (prevFile == null || !file.getName().equals(prevFile.getName()))) {
boolean overwrite = delegate.showWarningConfirm(LanguageBundle.getFormattedString(//$NON-NLS-1$
"in_savePcConfirmOverTitle", file.getName()), LanguageBundle.getFormattedString(//$NON-NLS-1$
"in_savePcConfirmOverMsg", file.getName()));
if (!overwrite) {
return showSaveCharacterChooser(character);
}
}
try {
character.setFile(file);
prepareForSave(character, false);
if (!reallySaveCharacter(character)) {
return showSaveCharacterChooser(character);
}
lastCharacterPath = chooser.getCurrentDirectory().toString();
return true;
} catch (Exception e) {
//$NON-NLS-1$
Logging.errorPrint("Error saving character to new file " + file, e);
delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("in_saveFailMsg", //$NON-NLS-1$
file.getName()));
}
}
return false;
}
Aggregations