Package fr.soleil.salsa.client.entity.event

Examples of fr.soleil.salsa.client.entity.event.DirectoryModel


     * Method called when the user clicks on the new directory button.
     */
    @Override
    public void notifyNewDirectory(String directoryName) {
        if (directoryName != null && !"".equals(directoryName.trim())) {
            DirectoryModel directory = new DirectoryModel();
            directory.setName(directoryName);
            if (currentDirectory == null) {
                currentDirectory = rootDirectory;
            }
            if (currentDirectory != null) {
                moveDirectory(directory, currentDirectory);
            }
            DirectoryModel savedDirectory = saveDirectory(directory);
            if (rootDirectory == null) {
                rootDirectory = savedDirectory;
            }
            currentDirectory = savedDirectory;
            refresh();
            ATreeNode treeNode = new DirectoryTreeNode(currentDirectory);
            if (savedDirectory.getDirectory() != null) {
                view.expandNode(new DirectoryTreeNode(savedDirectory.getDirectory()));
            }
            view.setSelection(treeNode);
        }
    }
View Full Code Here


                    }
                }
                else {
                    if (!isChild(target, treeNode)) {
                        DirectoryTreeNode directoryTreeNode = (DirectoryTreeNode) treeNode;
                        DirectoryModel movedDirectory = (DirectoryModel) directoryTreeNode
                                .getDirectory();
                        if (!movedDirectory.equals(targetDirectory)
                                && !targetDirectory.equals(movedDirectory.getDirectory())) {
                            moveDirectory(movedDirectory, targetDirectory);
                            directoryTreeNode.setDirectory(saveDirectory(movedDirectory));
                        }
                    }
                }
View Full Code Here

     * Copy and paste the directory in directoryTreeNode to the current directory.
     *
     * @param directoryTreeNode
     */
    private void copyPasteDirectory(DirectoryTreeNode directoryTreeNode) {
        DirectoryModel copiedDirectoryModel = (DirectoryModel) directoryTreeNode.getDirectory();

        // The configuration are not fully loaded when the configuration is first created to save
        // time.
        // We need to load all of the configurations contained in the directory and its
        // subdirectories to copy them too.
        loadConfigRecursive(copiedDirectoryModel);

        // To copy the object, we serialize it to a byte array, then we recover a copy from it.
        // This way, we can reuse the existing serialization rather than implement the clone
        // method on every entity.
        IDirectory copiedDirectory = (IDirectory) AutoCopier.toImpl(copiedDirectoryModel);
        DirectoryModel copyDirectoryModel;
        IDirectory copyDirectory;
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
            objectOutputStream.writeObject(copiedDirectory);
            byte[] buffer = byteArrayOutputStream.toByteArray();
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buffer);
            ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
            copyDirectory = (IDirectory) objectInputStream.readObject();
        }
        catch (IOException e) {
            // The streams work on the RAM, so an IOException should never happen.
            e.printStackTrace();
            copyDirectory = null;
        }
        catch (ClassNotFoundException e) {
            // This should never happen as well.
            e.printStackTrace();
            copyDirectory = null;
        }

        // copiedDirectoryModel needs to be rewrapped.
        /*DirectoryModel restoreCopiedDirectoryModel = DirectoryModelWrapperFactory.getInstance()
                .wrap(copiedDirectory);
        if (copiedDirectoryModel == currentDirectory) {
            currentDirectory = restoreCopiedDirectoryModel;
        }*/

        copyDirectory = AutoCopier.copyDirectoryToModel(copyDirectory);
        // We need to set the identifiers of the new directories and configurations to null.
        nullId(copyDirectory);
        moveDirectory(copyDirectory, currentDirectory);
        copyDirectoryModel = (DirectoryModel) copyDirectory;// DirectoryModelWrapperFactory.getInstance().wrap(copyDirectory);

        DirectoryModel savedDirectory = saveDirectoryRecursive(copyDirectoryModel);
        currentDirectory.getSubDirectoriesList().remove(copyDirectory);
        currentDirectory.getSubDirectoriesList().add(savedDirectory);
        directoryTreeNode.setDirectory(copiedDirectory);
    }
View Full Code Here

     * Cut and paste (move) the directory in directoryTreeNode to the current directory.
     *
     * @param directoryTreeNode
     */
    private void cutPasteDirectory(DirectoryTreeNode directoryTreeNode) {
        DirectoryModel movedDirectory = (DirectoryModel) directoryTreeNode.getDirectory();
        if (!movedDirectory.equals(currentDirectory)) {
            moveDirectory(movedDirectory, currentDirectory);
            directoryTreeNode.setDirectory(saveDirectory(movedDirectory));
        }
    }
View Full Code Here

     * @param directoryModel
     * @return
     */
    private DirectoryModel saveDirectory(DirectoryModel directoryModel) {
        // IDirectory directoryImpl = directoryModelWrapperFactory.unWrap(directoryModel);
        DirectoryModel savedDirectoryModel = null;
        try {
            savedDirectoryModel = (DirectoryModel) ConfigAPIClient.saveDirectory(directoryModel);

            if (directoryModel.getDirectory() != null && savedDirectoryModel.getDirectory() != null) {
                directoryModel.getDirectory().setTimestamp(
                        savedDirectoryModel.getDirectory().getTimestamp());
            }
            savedDirectoryModel.setDirectory(directoryModel.getDirectory());
            savedDirectoryModel.setConfigList(directoryModel.getConfigList());
            savedDirectoryModel.setSubDirectoriesList(directoryModel.getSubDirectoriesList());
            // savedDirectoryModel = directoryModelWrapperFactory.wrap(savedDirectoryImpl);
        }
        catch (PersistenceException e) {
            e.printStackTrace();
            applicationController.errorMessage("Error saving directory " + directoryModel.getName()
View Full Code Here

     * @param directoryModel
     * @return
     */
    private DirectoryModel saveDirectoryRecursive(DirectoryModel directoryModel) {
        directoryModel.setName(directoryModel.getName() + " (copy)");
        DirectoryModel savedDirectoryModel = saveDirectory(directoryModel);
        for (IDirectory subDirectory : savedDirectoryModel.getSubDirectoriesList()) {
            saveDirectoryRecursive((DirectoryModel) subDirectory);
        }
        for (IConfig config : savedDirectoryModel.getConfigList()) {
            config.setDirectory(savedDirectoryModel);
            config.setName(config.getName() + " (copy)");
            saveConfig(config);
        }
        return savedDirectoryModel;
View Full Code Here

     * Method called when the user clicks on the new directory button.
     */
    @Override
    public void notifyNewDirectory(String directoryName) {
        if (directoryName != null && !"".equals(directoryName.trim())) {
            DirectoryModel directory = new DirectoryModel();
            directory.setName(directoryName);
            if (currentDirectory == null) {
                currentDirectory = rootDirectory;
            }
            if (currentDirectory != null) {
                moveDirectory(directory, currentDirectory);
            }
            DirectoryModel savedDirectory = saveDirectory(directory);
            if (rootDirectory == null) {
                rootDirectory = savedDirectory;
            }
            currentDirectory = savedDirectory;
            refresh();
            ATreeNode treeNode = new DirectoryTreeNode(currentDirectory);
            if (savedDirectory.getDirectory() != null) {
                view.expandNode(new DirectoryTreeNode(savedDirectory.getDirectory()));
            }
            view.setSelection(treeNode);
        }
    }
View Full Code Here

                    }
                }
                else {
                    if (!isChild(target, treeNode)) {
                        DirectoryTreeNode directoryTreeNode = (DirectoryTreeNode) treeNode;
                        DirectoryModel movedDirectory = (DirectoryModel) directoryTreeNode
                                .getDirectory();
                        if (!movedDirectory.equals(targetDirectory)
                                && !targetDirectory.equals(movedDirectory.getDirectory())) {
                            moveDirectory(movedDirectory, targetDirectory);
                            directoryTreeNode.setDirectory(saveDirectory(movedDirectory));
                        }
                    }
                }
View Full Code Here

     * Copy and paste the directory in directoryTreeNode to the current directory.
     *
     * @param directoryTreeNode
     */
    private void copyPasteDirectory(DirectoryTreeNode directoryTreeNode) {
        DirectoryModel copiedDirectoryModel = (DirectoryModel) directoryTreeNode.getDirectory();

        // The configuration are not fully loaded when the configuration is first created to save
        // time.
        // We need to load all of the configurations contained in the directory and its
        // subdirectories to copy them too.
        loadConfigRecursive(copiedDirectoryModel);

        // To copy the object, we serialize it to a byte array, then we recover a copy from it.
        // This way, we can reuse the existing serialization rather than implement the clone
        // method on every entity.
        IDirectory copiedDirectory = (IDirectory) AutoCopier.toImpl(copiedDirectoryModel);
        DirectoryModel copyDirectoryModel;
        IDirectory copyDirectory;
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
            objectOutputStream.writeObject(copiedDirectory);
            byte[] buffer = byteArrayOutputStream.toByteArray();
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buffer);
            ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
            copyDirectory = (IDirectory) objectInputStream.readObject();
        }
        catch (IOException e) {
            // The streams work on the RAM, so an IOException should never happen.
            e.printStackTrace();
            copyDirectory = null;
        }
        catch (ClassNotFoundException e) {
            // This should never happen as well.
            e.printStackTrace();
            copyDirectory = null;
        }

        // copiedDirectoryModel needs to be rewrapped.
        /*DirectoryModel restoreCopiedDirectoryModel = DirectoryModelWrapperFactory.getInstance()
                .wrap(copiedDirectory);
        if (copiedDirectoryModel == currentDirectory) {
            currentDirectory = restoreCopiedDirectoryModel;
        }*/

        copyDirectory = AutoCopier.copyDirectoryToModel(copyDirectory);
        // We need to set the identifiers of the new directories and configurations to null.
        nullId(copyDirectory);
        moveDirectory(copyDirectory, currentDirectory);
        copyDirectoryModel = (DirectoryModel) copyDirectory;// DirectoryModelWrapperFactory.getInstance().wrap(copyDirectory);

        DirectoryModel savedDirectory = saveDirectoryRecursive(copyDirectoryModel);
        currentDirectory.getSubDirectoriesList().remove(copyDirectory);
        currentDirectory.getSubDirectoriesList().add(savedDirectory);
        directoryTreeNode.setDirectory(copiedDirectory);
    }
View Full Code Here

     * Cut and paste (move) the directory in directoryTreeNode to the current directory.
     *
     * @param directoryTreeNode
     */
    private void cutPasteDirectory(DirectoryTreeNode directoryTreeNode) {
        DirectoryModel movedDirectory = (DirectoryModel) directoryTreeNode.getDirectory();
        if (!movedDirectory.equals(currentDirectory)) {
            moveDirectory(movedDirectory, currentDirectory);
            directoryTreeNode.setDirectory(saveDirectory(movedDirectory));
        }
    }
View Full Code Here

TOP

Related Classes of fr.soleil.salsa.client.entity.event.DirectoryModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.