Search in sources :

Example 36 with Observable

use of java.util.Observable in project hale by halestudio.

the class TransformationView method createViewControl.

/**
 * @see eu.esdihumboldt.hale.ui.views.mapping.AbstractMappingView#createViewControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createViewControl(Composite parent) {
    super.createViewControl(parent);
    IActionBars bars = getViewSite().getActionBars();
    bars.getToolBarManager().add(instanceAction = new Action("Apply sample instances", IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            update();
        }
    });
    instanceAction.setImageDescriptor(TransformationViewPlugin.getImageDescriptor("icons/samples.gif"));
    instanceAction.setChecked(initInstanceAction);
    update();
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    as.addListener(alignmentListener = new AlignmentServiceAdapter() {

        @Override
        public void alignmentCleared() {
            update();
        }

        @Override
        public void cellsRemoved(Iterable<Cell> cells) {
            update();
        }

        @Override
        public void cellsReplaced(Map<? extends Cell, ? extends Cell> cells) {
            update();
        }

        @Override
        public void cellsAdded(Iterable<Cell> cells) {
            update();
        }

        @Override
        public void alignmentChanged() {
            update();
        }

        @Override
        public void customFunctionsChanged() {
            update();
        }

        @Override
        public void cellsPropertyChanged(Iterable<Cell> cells, String propertyName) {
            if (Cell.PROPERTY_DISABLE_FOR.equals(propertyName) || Cell.PROPERTY_ENABLE_FOR.equals(propertyName))
                // Could add/remove cells from transformation tree
                update();
            else {
                final Display display = PlatformUI.getWorkbench().getDisplay();
                display.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        // refresh view
                        getViewer().refresh();
                    }
                });
            }
        }
    });
    final InstanceSampleService iss = PlatformUI.getWorkbench().getService(InstanceSampleService.class);
    iss.addObserver(instanceSampleObserver = new Observer() {

        @SuppressWarnings("unchecked")
        @Override
        public void update(Observable o, Object arg) {
            if (!instanceAction.isChecked()) {
                return;
            }
            Object input = getViewer().getInput();
            Collection<Instance> oldInstances = null;
            int sampleCount = 0;
            if (input instanceof Pair<?, ?>) {
                Object second = ((Pair<?, ?>) input).getSecond();
                if (second instanceof Collection<?>) {
                    oldInstances = (Collection<Instance>) second;
                    sampleCount = oldInstances.size();
                }
            }
            Collection<Instance> newSamples = iss.getReferenceInstances();
            if (sampleCount == newSamples.size()) {
                // still to decide if update is necessary
                if (sampleCount == 0) {
                    return;
                }
                // check if instances equal?
                Set<Instance> test = new HashSet<Instance>(oldInstances);
                test.removeAll(newSamples);
                if (test.isEmpty()) {
                    return;
                }
            }
            TransformationView.this.update();
        }
    });
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) Observable(java.util.Observable) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) Observer(java.util.Observer) InstanceSampleService(eu.esdihumboldt.hale.ui.service.instance.sample.InstanceSampleService) Collection(java.util.Collection) AlignmentServiceAdapter(eu.esdihumboldt.hale.ui.service.align.AlignmentServiceAdapter) Map(java.util.Map) Cell(eu.esdihumboldt.hale.common.align.model.Cell) IActionBars(org.eclipse.ui.IActionBars) Display(org.eclipse.swt.widgets.Display) Pair(eu.esdihumboldt.util.Pair) HashSet(java.util.HashSet)

Example 37 with Observable

use of java.util.Observable in project podam by devopsfolks.

the class ConstructorsUnitTest method podamShouldBeAbleToManufactureInstancesOfTheObservableClass.

@Test
@Title("Podam should be able to manufacture instances of the Observable class")
public void podamShouldBeAbleToManufactureInstancesOfTheObservableClass() throws Exception {
    PodamFactory podamFactory = podamFactorySteps.givenAStandardPodamFactory();
    Observable observable = podamInvocationSteps.whenIInvokeTheFactoryForClass(Observable.class, podamFactory);
    podamValidationSteps.thePojoMustBeOfTheType(observable, Observable.class);
}
Also used : PodamFactory(uk.co.jemos.podam.api.PodamFactory) Observable(java.util.Observable) Test(org.junit.Test) Title(net.thucydides.core.annotations.Title)

Example 38 with Observable

use of java.util.Observable in project j2objc by google.

the class ObservableTest method test_observableWithOverridenHasChanged.

// http://b/28797950
public void test_observableWithOverridenHasChanged() throws Exception {
    final AtomicReference<Observable> updated = new AtomicReference<>();
    final Observer observer = (observable1, data) -> updated.set(observable1);
    Observable alwaysChanging = new AlwaysChangedObservable();
    alwaysChanging.addObserver(observer);
    alwaysChanging.notifyObservers(null);
    assertSame(alwaysChanging, updated.get());
}
Also used : Observer(java.util.Observer) Vector(java.util.Vector) Observable(java.util.Observable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Observer(java.util.Observer) AtomicReference(java.util.concurrent.atomic.AtomicReference) Observable(java.util.Observable)

Example 39 with Observable

use of java.util.Observable in project jPOS by jpos.

the class ISOServer method run.

// inner class Session
// -------------------------------------------------------------------------------
// -- This is the main run for this ISOServer's Thread
@Override
public void run() {
    ServerChannel channel;
    if (socketFactory == null) {
        socketFactory = this;
    }
    serverLoop: while (!shutdown) {
        try {
            serverSocket = socketFactory.createServerSocket(port);
            Logger.log(new LogEvent(this, "iso-server", "listening on " + (bindAddr != null ? bindAddr + ":" : "port ") + port + (backlog > 0 ? " backlog=" + backlog : "")));
            while (!shutdown) {
                try {
                    if (pool.getAvailableCount() <= 0) {
                        try {
                            serverSocket.close();
                            fireEvent(new ISOServerShutdownEvent(this));
                        } catch (IOException e) {
                            Logger.log(new LogEvent(this, "iso-server", e));
                            relax();
                        }
                        for (int i = 0; pool.getIdleCount() == 0; i++) {
                            if (shutdown) {
                                break serverLoop;
                            }
                            if (i % 240 == 0 && cfg.getBoolean("pool-exhaustion-warning", true)) {
                                LogEvent evt = new LogEvent(this, "warn");
                                evt.addMessage("pool exhausted " + serverSocket.toString());
                                evt.addMessage(pool);
                                Logger.log(evt);
                            }
                            ISOUtil.sleep(250);
                        }
                        serverSocket = socketFactory.createServerSocket(port);
                    }
                    channel = (ServerChannel) clientSideChannel.clone();
                    channel.accept(serverSocket);
                    if (cnt[CONNECT]++ % 100 == 0) {
                        purgeChannels();
                    }
                    WeakReference wr = new WeakReference(channel);
                    channels.put(channel.getName(), wr);
                    channels.put(LAST, wr);
                    pool.execute(createSession(channel));
                    setChanged();
                    notifyObservers(this);
                    fireEvent(new ISOServerAcceptEvent(this, channel));
                    if (channel instanceof Observable) {
                        ((Observable) channel).addObserver(this);
                    }
                } catch (SocketException e) {
                    if (!shutdown) {
                        Logger.log(new LogEvent(this, "iso-server", e));
                        relax();
                        continue serverLoop;
                    }
                } catch (IOException e) {
                    Logger.log(new LogEvent(this, "iso-server", e));
                    relax();
                }
            }
        // while !shutdown
        } catch (Throwable e) {
            Logger.log(new LogEvent(this, "iso-server", e));
            relax();
        }
    }
}
Also used : SocketException(java.net.SocketException) LogEvent(org.jpos.util.LogEvent) WeakReference(java.lang.ref.WeakReference) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Observable(java.util.Observable)

Example 40 with Observable

use of java.util.Observable in project AutoRefactor by JnRouvignac.

the class SetRatherThanListSample method refactorWithLinkedListMethod.

public boolean refactorWithLinkedListMethod() {
    // Keep this comment
    HashSet<Observable> collection = new HashSet<Observable>();
    // Keep this comment too
    collection.add(new Observable());
    return collection.contains(new Observable());
}
Also used : Observable(java.util.Observable) HashSet(java.util.HashSet)

Aggregations

Observable (java.util.Observable)52 Observer (java.util.Observer)30 Test (org.junit.Test)8 ContentQueryMap (android.content.ContentQueryMap)6 ContentResolver (android.content.ContentResolver)6 ContentValues (android.content.ContentValues)6 Cursor (android.database.Cursor)6 Handler (android.os.Handler)6 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 LinkedList (java.util.LinkedList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 MessagePanel (edu.ucsf.rbvi.clusterMaker2.internal.treeview.MessagePanel)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 IJobChangeListener (org.eclipse.core.runtime.jobs.IJobChangeListener)2 Job (org.eclipse.core.runtime.jobs.Job)2 KeyStoreAlias (org.jcryptool.crypto.keystore.backend.KeyStoreAlias)2 WithDumpException (com.github.mob41.osumer.debug.WithDumpException)1 OsuDownloader (com.github.mob41.osumer.io.OsuDownloader)1