Search in sources :

Example 1 with Tuple

use of org.jowidgets.util.Tuple in project jo-client-platform by jo-source.

the class BeanRelationTreeImpl method renderEndOfPageDummyNode.

private void renderEndOfPageDummyNode(final ITreeNode node, final IBeanProxy<Object> bean, final IBeanRelationNodeModel<Object, Object> relationNodeModel) {
    node.setText(LOAD_MORE_DATASETS_LABEL.get());
    node.setToolTipText(LOAD_MORE_DATASETS_TOOLTIP.get());
    node.setMarkup(Markup.EMPHASIZED);
    node.setForegroundColor(Colors.STRONG);
    final TreeNodeAdapter loadPageListener = new TreeNodeAdapter() {

        @Override
        public void selectionChanged(final boolean selected) {
            if (selected) {
                Toolkit.getUiThreadAccess().invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        final Tuple<IBeanRelationNodeModel<Object, Object>, IBeanProxy<Object>> tuple = nodesMap.get(node);
                        if (tuple != null) {
                            node.dispose();
                            tuple.getFirst().loadNextPage();
                        }
                    }
                });
            }
        }
    };
    node.addTreeNodeListener(loadPageListener);
}
Also used : TreeNodeAdapter(org.jowidgets.tools.controller.TreeNodeAdapter) Tuple(org.jowidgets.util.Tuple)

Example 2 with Tuple

use of org.jowidgets.util.Tuple in project jo-client-platform by jo-source.

the class InvocationClientImpl method getResponseService.

@Override
public IResponseService getResponseService() {
    return new IResponseService() {

        @Override
        public void response(final Object requestId, final Object response) {
            Assert.paramNotNull(requestId, "requestId");
            final TimeStampedObject<Tuple<Object, IMessageChannel>> request = interimRequests.remove(requestId);
            if (request != null) {
                final Tuple<Object, IMessageChannel> tuple = request.getObject();
                final ResponseMessage message = new ResponseMessage(requestId, response);
                tuple.getSecond().send(message, new ExceptionCallback(invocationClientServiceRegistry, tuple.getFirst()));
            } else {
                throw new IllegalStateException("The request id '" + requestId + "' is not known");
            }
        }
    };
}
Also used : IResponseService(org.jowidgets.invocation.common.api.IResponseService) ResponseMessage(org.jowidgets.invocation.common.impl.ResponseMessage) IMessageChannel(org.jowidgets.message.api.IMessageChannel) Tuple(org.jowidgets.util.Tuple)

Example 3 with Tuple

use of org.jowidgets.util.Tuple in project jo-client-platform by jo-source.

the class TemplateReplacer method copyAndReplace.

public static void copyAndReplace(final String[] args, final ReplacementConfig config) throws Exception {
    if (args.length != 2) {
        // CHECKSTYLE:OFF
        System.out.println("Usage: " + TemplateReplacer.class.getSimpleName() + " <sourceDirectory> <destinationDirectory>");
        // CHECKSTYLE:ON
        return;
    }
    final File source = new File(args[0]);
    if (!source.exists() || !source.isDirectory()) {
        // CHECKSTYLE:OFF
        System.out.println("Source directory doesn't exist: " + source);
        // CHECKSTYLE:ON
        return;
    }
    final File destination = new File(args[1]);
    if (destination.exists()) {
        // CHECKSTYLE:OFF
        System.out.println("Destination directory is not empty: " + destination);
        // CHECKSTYLE:ON
        return;
    }
    final String encoding = config.getEncoding();
    Collection<Tuple<String, String>> replacements = new HashSet<Tuple<String, String>>(config.getReplacements());
    final Collection<Tuple<String[], String[]>> packageReplacements = config.getPackageReplacements();
    replacements.addAll(getReplacementsFromPackageReplacements(packageReplacements));
    replacements = getSortedReplacements(replacements);
    Collection<Tuple<String, String>> pathReplacements = getPathReplacementsFromPackageReplacements(packageReplacements);
    pathReplacements.addAll(replacements);
    pathReplacements = getSortedReplacements(pathReplacements);
    final IOFileFilter targetFilter = FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter("target"));
    final IOFileFilter directoryFilter = FileFilterUtils.makeSVNAware(targetFilter);
    final IOFileFilter pomFileFilter = FileFilterUtils.nameFileFilter("pom.xml", IOCase.INSENSITIVE);
    final IOFileFilter javaFileFilter = FileFilterUtils.suffixFileFilter("java", IOCase.INSENSITIVE);
    final int sourcePathLength = source.getPath().length();
    for (final File file : list(source, directoryFilter)) {
        String subPath = replace(file.getPath().substring(sourcePathLength), pathReplacements);
        subPath = replace(subPath, replacements);
        final File destinationFile = new File(destination.getPath() + subPath);
        if (file.isDirectory()) {
            if (!destinationFile.exists()) {
                if (!ignorePath(destinationFile, packageReplacements)) {
                    if (!destinationFile.mkdirs()) {
                        throw new IllegalStateException("Failed to create directory: " + destinationFile);
                    }
                }
            }
        } else {
            final Tuple<IOFileFilter, String> fileReplacement = getFileReplacement(destinationFile, config.getFileReplacements());
            if (fileReplacement != null) {
                if (!EmptyCheck.isEmpty(fileReplacement.getSecond())) {
                    FileUtils.writeStringToFile(destinationFile, fileReplacement.getSecond(), encoding);
                }
            } else if (config.getJavaHeader() != null && javaFileFilter.accept(destinationFile)) {
                String text = FileUtils.readFileToString(file, encoding);
                if (config.getModififyFilesFilter().accept(destinationFile)) {
                    text = replace(text, replacements);
                }
                final int startIndex = text.indexOf("/*");
                int endIndex = text.indexOf("*/");
                if (startIndex != -1 && endIndex != -1) {
                    endIndex += 2;
                    text = text.substring(0, startIndex) + config.getJavaHeader() + text.substring(endIndex, text.length());
                }
                FileUtils.writeStringToFile(destinationFile, text, encoding);
            } else if (config.getParentPomVersion() != null && pomFileFilter.accept(destinationFile)) {
                String text = FileUtils.readFileToString(file, encoding);
                if (config.getModififyFilesFilter().accept(destinationFile)) {
                    text = replace(text, replacements);
                }
                int parentStartIndex = text.indexOf("<parent>");
                final int parentEndIndex = text.indexOf("</parent>");
                if (parentStartIndex != -1 && parentEndIndex != -1) {
                    parentStartIndex += 8;
                    String parentText = text.substring(parentStartIndex, parentEndIndex);
                    final String replacement = "<version>" + config.getParentPomVersion() + "</version>";
                    parentText = parentText.replaceAll("<version>.*</version>", replacement);
                    text = text.substring(0, parentStartIndex) + parentText + text.substring(parentEndIndex, text.length());
                }
                FileUtils.writeStringToFile(destinationFile, text, encoding);
            } else if (config.getModififyFilesFilter().accept(destinationFile)) {
                String text = FileUtils.readFileToString(file, encoding);
                text = replace(text, replacements);
                FileUtils.writeStringToFile(destinationFile, text, encoding);
            } else {
                FileUtils.copyFile(file, destinationFile);
            }
        }
    }
}
Also used : IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) File(java.io.File) Tuple(org.jowidgets.util.Tuple) HashSet(java.util.HashSet)

Example 4 with Tuple

use of org.jowidgets.util.Tuple in project jo-client-platform by jo-source.

the class TemplateReplacer method createConfig.

private static ReplacementConfig createConfig() {
    final ReplacementConfig config = new ReplacementConfig();
    final Set<Tuple<String, String>> replacements = new HashSet<Tuple<String, String>>();
    replacements.add(new Tuple<String, String>("TemplateSample1", "MongodbSample1"));
    replacements.add(new Tuple<String, String>("Sample1", "Sample1"));
    replacements.add(new Tuple<String, String>("sample1", "sample1"));
    // replacements.add(new Tuple<String, String>("<vendor>jowidgets.org</vendor>", "<vendor>myorg.de</vendor>"));
    config.setReplacements(replacements);
    final Set<Tuple<String[], String[]>> packageReplacements = new HashSet<Tuple<String[], String[]>>();
    final String[] packageReplacementSource = new String[] { "org", "jowidgets", "samples", "template", "sample1" };
    final String[] packageReplacementDestination = new String[] { "org", "jowidgets", "samples", "mongodb", "sample1" };
    packageReplacements.add(new Tuple<String[], String[]>(packageReplacementSource, packageReplacementDestination));
    config.setPackageReplacements(packageReplacements);
    final IOFileFilter modifyFilesFilter = new SuffixFileFilter(new String[] { "java", "project", "xml", "MF", "htm", "html", "jnlp", "template.vm", "org.jowidgets.cap.ui.api.login.ILoginService", "org.jowidgets.security.api.IAuthenticationService", "org.jowidgets.security.api.IAuthorizationService", "org.jowidgets.service.api.IServiceProviderHolder" }, IOCase.INSENSITIVE);
    config.setModififyFilesFilter(modifyFilesFilter);
    // config.setJavaHeader("/* \n * Copyright (c) 2013 \n */");
    config.setParentPomVersion("0.0.1-SNAPSHOT");
    return config;
}
Also used : IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) Tuple(org.jowidgets.util.Tuple) HashSet(java.util.HashSet)

Example 5 with Tuple

use of org.jowidgets.util.Tuple in project jo-client-platform by jo-source.

the class SyncNeo4JSimpleRelatedReaderServiceImpl method getAllRelatedNodes.

private List<Tuple<Node, Relationship>> getAllRelatedNodes(final List<Tuple<Node, Relationship>> parentNodes, final Tuple<RelationshipType, Direction> relation, final IExecutionCallback executionCallback) {
    final List<Tuple<Node, Relationship>> result = new LinkedList<Tuple<Node, Relationship>>();
    final RelationshipType relationshipType = relation.getFirst();
    final Direction direction = relation.getSecond();
    for (final Tuple<Node, Relationship> parentNodeTuple : parentNodes) {
        CapServiceToolkit.checkCanceled(executionCallback);
        final Node parentNode = parentNodeTuple.getFirst();
        for (final Relationship relationship : parentNode.getRelationships(direction, relationshipType)) {
            CapServiceToolkit.checkCanceled(executionCallback);
            result.add(new Tuple<Node, Relationship>(relationship.getOtherNode(parentNode), relationship));
        }
    }
    return result;
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) Direction(org.neo4j.graphdb.Direction) Tuple(org.jowidgets.util.Tuple) LinkedList(java.util.LinkedList)

Aggregations

Tuple (org.jowidgets.util.Tuple)7 LinkedList (java.util.LinkedList)3 HashSet (java.util.HashSet)2 List (java.util.List)2 IOFileFilter (org.apache.commons.io.filefilter.IOFileFilter)2 File (java.io.File)1 SuffixFileFilter (org.apache.commons.io.filefilter.SuffixFileFilter)1 IResponseService (org.jowidgets.invocation.common.api.IResponseService)1 ResponseMessage (org.jowidgets.invocation.common.impl.ResponseMessage)1 IMessageChannel (org.jowidgets.message.api.IMessageChannel)1 IPluginFilter (org.jowidgets.plugin.api.IPluginFilter)1 TreeNodeAdapter (org.jowidgets.tools.controller.TreeNodeAdapter)1 Direction (org.neo4j.graphdb.Direction)1 Node (org.neo4j.graphdb.Node)1 Relationship (org.neo4j.graphdb.Relationship)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1