Search in sources :

Example 6 with IModelChangeMessage

use of org.eclipse.ecf.sync.IModelChangeMessage in project ecf by eclipse.

the class SyncResourcesCore method distributeChanges.

private void distributeChanges() {
    for (Iterator it = resourceChanges.entrySet().iterator(); it.hasNext(); ) {
        Entry entry = (Entry) it.next();
        ResourcesShare share = (ResourcesShare) entry.getKey();
        List changes = (List) entry.getValue();
        List messages = new ArrayList();
        for (int i = 0; i < changes.size(); i++) {
            ResourceChangeMessage change = (ResourceChangeMessage) changes.get(i);
            switch(change.getKind()) {
                case IResourceDelta.ADDED:
                    if (getInt(PreferenceConstants.LOCAL_RESOURCE_ADDITION) == PreferenceConstants.IGNORE_VALUE) {
                        change.setIgnored(true);
                        continue;
                    }
                    break;
                case IResourceDelta.CHANGED:
                    if (getInt(PreferenceConstants.LOCAL_RESOURCE_CHANGE) == PreferenceConstants.IGNORE_VALUE) {
                        change.setIgnored(true);
                        continue;
                    }
                    break;
                case IResourceDelta.REMOVED:
                    if (getInt(PreferenceConstants.LOCAL_RESOURCE_DELETION) == PreferenceConstants.IGNORE_VALUE) {
                        change.setIgnored(true);
                        continue;
                    }
                    break;
            }
            IModelChangeMessage[] changeMessages = ResourcesSynchronizationStrategy.getInstance().registerLocalChange(change);
            messages.addAll(Arrays.asList(changeMessages));
        }
        try {
            if (!messages.isEmpty()) {
                IModelChangeMessage[] messagesArray = (IModelChangeMessage[]) messages.toArray(new IModelChangeMessage[messages.size()]);
                BatchModelChange batchChange = new BatchModelChange(messagesArray);
                share.send(Message.serialize(batchChange));
                add(batchChange);
            }
        } catch (ECFException e) {
            getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, "Could not send resource change message", // $NON-NLS-1$
            e));
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Entry(java.util.Map.Entry) ECFException(org.eclipse.ecf.core.util.ECFException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) IModelChangeMessage(org.eclipse.ecf.sync.IModelChangeMessage)

Aggregations

IModelChangeMessage (org.eclipse.ecf.sync.IModelChangeMessage)6 SerializationException (org.eclipse.ecf.sync.SerializationException)3 ECFException (org.eclipse.ecf.core.util.ECFException)2 IModelChange (org.eclipse.ecf.sync.IModelChange)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 DocumentChangeMessage (org.eclipse.ecf.sync.doc.DocumentChangeMessage)1