Search in sources :

Example 1 with CharacterFacadeImpl

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;
}
Also used : CharacterFacade(pcgen.facade.core.CharacterFacade) CharacterFacadeImpl(pcgen.gui2.facade.CharacterFacadeImpl)

Example 2 with CharacterFacadeImpl

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;
    }
}
Also used : PlayerCharacterWasLoadedMessage(pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage) PlayerCharacter(pcgen.core.PlayerCharacter) ArrayList(java.util.ArrayList) List(java.util.List) CharacterFacade(pcgen.facade.core.CharacterFacade) IOException(java.io.IOException) CharacterFacadeImpl(pcgen.gui2.facade.CharacterFacadeImpl)

Example 3 with CharacterFacadeImpl

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;
}
Also used : IOException(java.io.IOException) PCGFile(pcgen.io.PCGFile) File(java.io.File) CharacterFacadeImpl(pcgen.gui2.facade.CharacterFacadeImpl) UIDelegate(pcgen.facade.core.UIDelegate)

Aggregations

CharacterFacadeImpl (pcgen.gui2.facade.CharacterFacadeImpl)3 IOException (java.io.IOException)2 CharacterFacade (pcgen.facade.core.CharacterFacade)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PlayerCharacter (pcgen.core.PlayerCharacter)1 UIDelegate (pcgen.facade.core.UIDelegate)1 PCGFile (pcgen.io.PCGFile)1 PlayerCharacterWasLoadedMessage (pcgen.pluginmgr.messages.PlayerCharacterWasLoadedMessage)1