Package org.locationtech.udig.project.internal

Examples of org.locationtech.udig.project.internal.StyleEntry


        clone.content = null;

        contentLock.lock();
        try {
            for (Iterator seItr = getContent().iterator(); seItr.hasNext();) {
                StyleEntry styleEntry = (StyleEntry) seItr.next();

                StyleEntry styleEntryClone = ProjectFactory.eINSTANCE.createStyleEntry();

                // clone the entry by copying the id + memento over
                final String ID = styleEntry.getID();
                styleEntryClone.setID(ID);
                styleEntryClone.setMemento(styleEntry.getMemento());

                Object style = styleEntry.getStyle();
                if (style instanceof String) {
                    styleEntryClone.setStyle(style); // immutable
                } else if (style instanceof Serializable) {
                    try {
                        Serializable serializable = (Serializable) style;
                        ByteArrayOutputStream save = new ByteArrayOutputStream();
                        ObjectOutputStream out = new ObjectOutputStream(save);
                        out.writeObject(style);
                        out.close();

                        byte data[] = save.toByteArray();

                        ByteArrayInputStream restore = new ByteArrayInputStream(data);
                        ObjectInputStream in = new ObjectInputStream(restore);

                        Object copy = in.readObject();
                        in.close();

                        styleEntryClone.setStyle(copy);
                    } catch (Throwable t) {
                        ProjectPlugin.trace(StyleBlackboardImpl.class, "Unable to copy style " + ID
                                + ":" + style, t);
                    }
                } else {
                    // unable to preserve independence of this style object
                    styleEntryClone.setStyle(style); // warning!
                    ProjectPlugin.trace(StyleBlackboardImpl.class, "Unable to copy style " + ID
                            + ":" + style, null);
                }
                clone.getContent().add(styleEntryClone);
            }
View Full Code Here


        }

    }

    public boolean isSelected(String styleId) {
        StyleEntry entry = getEntry(styleId);

        if (entry != null && entry.isSelected())
            return true;
        return false;
    }
View Full Code Here

            if (result == null)
                result = defaultCase(theEObject);
            return result;
        }
        case ProjectPackage.STYLE_ENTRY: {
            StyleEntry styleEntry = (StyleEntry) theEObject;
            T result = caseStyleEntry(styleEntry);
            if (result == null)
                result = defaultCase(theEObject);
            return result;
        }
View Full Code Here

     * <!-- begin-user-doc --> <!-- end-user-doc -->
     *
     * @generated NOT
     */
    public Object get(String styleId) {
        StyleEntry entry = getEntry(styleId);
        if (entry == null)
            return null;
        return getObject(entry);
    }
View Full Code Here

            return null;
        return getObject(entry);
    }

    private StyleEntry getEntry(String styleId) {
        StyleEntry entry = null;
        contentLock.lock();
        try {
            for (Iterator seItr = getContent().iterator(); seItr.hasNext();) {
                StyleEntry se = (StyleEntry) seItr.next();
                if (se.getID().equals(styleId)) {
                    entry = se;
                    break;
                }
            }
        } finally {
View Full Code Here

     * <!-- begin-user-doc --> <!-- end-user-doc -->
     *
     * @generated NOT
     */
    public Object lookup(Class<?> theClass) {
        StyleEntry entry = null;
        contentLock.lock();
        try {
            for (Iterator seItr = getContent().iterator(); seItr.hasNext();) {
                StyleEntry se = (StyleEntry) seItr.next();
                try {
                    if (se.getStyleClass() == null) {
                        StyleContent styleContent = getStyleContent(se.getID());
                        if (styleContent != null) {
                            Class<?> type = styleContent.getStyleClass();
                            if (type == null) {
                                se.getStyle(); // force the load
                                type = styleContent.getStyleClass();
                                if (type == null) {
                                    continue;
                                }
                            }
                            se.setStyleClass(type);
                        } else {
                            // this shoudl no longer happen as we have a DEFAULT
                            continue;
                        }
                    }
                    if (theClass.isAssignableFrom(se.getStyleClass())) {
                        entry = se;
                        break;
                    }
                } catch (Throwable t) {
                    // protect against a StyleEntry/StyleContent taking us down
                    ProjectPlugin.log(
                            "Style " + se.getID() + " not restored:" + t.getLocalizedMessage(), t);
                }

            }
        } finally {
            contentLock.unlock();
View Full Code Here

     * @generated NOT
     */
    @SuppressWarnings("unchecked")
    public void put(String styleId, Object style) {
        Object oldValue = remove(styleId);
        StyleEntry se = ProjectFactory.eINSTANCE.createStyleEntry();

        se.setID(styleId);
        se.setStyle(style);

        content.add(se);

        StyleContent styleContent = getStyleContent(styleId);

        if (styleContent == null) {

            return;
        }
        try {
            // save the state of the style
            XMLMemento memento = XMLMemento.createWriteRoot("styleEntry"); //$NON-NLS-1$
            styleContent.save(memento, style);

            StringWriter writer = new StringWriter();
            memento.save(writer);
            se.setMemento(writer.getBuffer().toString());

            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
View Full Code Here

    public Object remove(String styleId) {
        Object style = null;
        contentLock.lock();
        try {
            for (Iterator seItr = getContent().iterator(); seItr.hasNext();) {
                StyleEntry se = (StyleEntry) seItr.next();
                if (se.getID().equals(styleId)) {
                    style = se.getStyle();
                    seItr.remove();
                }
            }
        } finally {
            contentLock.unlock();
View Full Code Here

    public void run( IProgressMonitor monitor ) throws Exception {
        // FIXME: This is a temporary solution
        List<StyleEntry> l = new ArrayList<StyleEntry>(newStyleBlackboard.getContent());
        List<String> selected = new ArrayList<String>();
        for( Iterator< ? > itr = l.iterator(); itr.hasNext(); ) {
            StyleEntry entry = (StyleEntry) itr.next();
            if (entry.getStyle() != null) {
                newStyleBlackboard.put(entry.getID(), entry.getStyle());
            }
        }
        newStyleBlackboard.setSelected(selected.toArray(new String[selected.size()]));
        layer.setStyleBlackboard(newStyleBlackboard);
    }
View Full Code Here

TOP

Related Classes of org.locationtech.udig.project.internal.StyleEntry

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.