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();
}
});
}
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);
}
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());
}
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();
}
}
}
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());
}
Aggregations