use of pcgen.gui2.facade.CharacterFacadeImpl in project pcgen by PCGen.
the class CharacterManager method createChracterFacade.
private static CharacterFacade createChracterFacade(UIDelegate delegate, DataSetFacade dataset, final PlayerCharacter newPC) {
CharacterFacade character = new CharacterFacadeImpl(newPC, delegate, dataset);
characters.addElement(character);
return character;
}
use of pcgen.gui2.facade.CharacterFacadeImpl in project pcgen by PCGen.
the class CharacterManager method createNewCharacter.
/**
* Create a new character using the supplied data sets.
* @param delegate the UIDelegate that this character will use.
* @param dataset the dataset that this will be loaded with.
* @return The character that was created.
*/
public static CharacterFacade createNewCharacter(UIDelegate delegate, DataSetFacade dataset) {
@SuppressWarnings("rawtypes") List campaigns = ListFacades.wrap(dataset.getCampaigns());
try {
@SuppressWarnings("unchecked") PlayerCharacter pc = new PlayerCharacter(campaigns);
Globals.getPCList().add(pc);
CharacterFacade character = new CharacterFacadeImpl(pc, delegate, dataset);
String name = createNewCharacterName();
character.setName(name);
characters.addElement(character);
//$NON-NLS-1$ //$NON-NLS-2$
Logging.log(Logging.INFO, "Created new character " + name + '.');
messageHandler.handleMessage(new PlayerCharacterWasLoadedMessage(delegate, pc));
return character;
} catch (final Exception e) {
Logging.errorPrint(//$NON-NLS-1$
"Unable to create character with data " + dataset, e);
delegate.showErrorMessage(//$NON-NLS-1$
LanguageBundle.getString("in_cmCreateErrorTitle"), //$NON-NLS-1$
LanguageBundle.getFormattedString(//$NON-NLS-1$
"in_cmCreateErrorMessage", e.getMessage()));
return null;
}
}
use of pcgen.gui2.facade.CharacterFacadeImpl 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;
}
Aggregations