Skip to content

Commit

Permalink
feat: Add JFace Snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
unknowIfGuestInDream committed Jun 30, 2024
1 parent cb7fa00 commit 7f9199c
Show file tree
Hide file tree
Showing 233 changed files with 31,294 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/org.eclipse.jface.examples.databinding/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.jface.examples.databinding</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jface.examples.databinding
Bundle-Version: 1.4.400.qualifier
Eclipse-BundleShape: dir
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Require-Bundle: org.eclipse.jface,
org.eclipse.core.databinding,
org.eclipse.core.runtime,
org.eclipse.core.databinding.beans,
org.eclipse.jface.databinding,
org.eclipse.core.databinding.property
Export-Package: org.eclipse.jface.examples.databinding;x-internal:=false,
org.eclipse.jface.examples.databinding.mask;x-internal:=false,
org.eclipse.jface.examples.databinding.mask.internal;x-internal:=true,
org.eclipse.jface.examples.databinding.model;x-internal:=false,
org.eclipse.jface.examples.databinding.radioGroup;x-internal:=false
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: org.eclipse.jface.examples.databinding
36 changes: 36 additions & 0 deletions examples/org.eclipse.jface.examples.databinding/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>About</title>
</head>
<body lang="EN-US">
<h2>About This Content</h2>

<p>November 30, 2017</p>
<h3>License</h3>

<p>
The Eclipse Foundation makes available all content in this plug-in
(&quot;Content&quot;). Unless otherwise indicated below, the Content
is provided to you under the terms and conditions of the Eclipse
Public License Version 2.0 (&quot;EPL&quot;). A copy of the EPL is
available at <a href="http://www.eclipse.org/legal/epl-2.0">http://www.eclipse.org/legal/epl-2.0</a>.
For purposes of the EPL, &quot;Program&quot; will mean the Content.
</p>

<p>
If you did not receive this Content directly from the Eclipse
Foundation, the Content is being redistributed by another party
(&quot;Redistributor&quot;) and different terms and conditions may
apply to your use of any object code in the Content. Check the
Redistributor's license that was provided with the Content. If no such
license exists, contact the Redistributor. Unless otherwise indicated
below, the terms and conditions of the EPL still apply to any source
code in the Content and such source code may be obtained at <a
href="http://www.eclipse.org/">http://www.eclipse.org</a>.
</p>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bin.includes = .,\
META-INF/,\
plugin.properties,\
about.html
src.includes = about.html
source.. = src/
output.. = bin/
javacWarnings..=-raw,unchecked .
15 changes: 15 additions & 0 deletions examples/org.eclipse.jface.examples.databinding/plugin.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
###############################################################################
# Copyright (c) 2000, 2005 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
pluginName = JFace Data Binding Examples
providerName = Eclipse.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*******************************************************************************
* Copyright (c) 2005, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jface.examples.databinding;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ModelObject {
private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
private String id;

public void addPropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(listener);
}

public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
}

public void removePropertyChangeListener(PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(listener);
}

public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
}

protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
}

protected void firePropertyChange(String propertyName, int oldValue, int newValue) {
propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
}

protected void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
}

public void setId(String string) {
Object oldValue = id;
id = string;
firePropertyChange("id", oldValue, id);
}

protected Object[] append(Object[] array, Object object) {
List<Object> newList = new ArrayList<>(Arrays.asList(array));
newList.add(object);
return newList.toArray((Object[]) Array.newInstance(array.getClass().getComponentType(), newList.size()));
}

protected Object[] remove(Object[] array, Object object) {
List<Object> newList = new ArrayList<>(Arrays.asList(array));
newList.remove(object);
return newList.toArray((Object[]) Array.newInstance(array.getClass().getComponentType(), newList.size()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*******************************************************************************
* Copyright (c) 2005, 2018 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jface.examples.databinding.contentprovider.test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;

import org.eclipse.core.databinding.observable.Diffs;
import org.eclipse.core.databinding.observable.set.ObservableSet;
import org.eclipse.swt.widgets.Display;

/**
* Test set that simulates asynchronously computed elements. The elements of the
* set are randomly generated Integers. Whenever the "recompute" method is
* called, the set will spin off a job that sleeps for a period of time and then
* randomly adds and removes elements from the set.
*
* <p>
* This simulates a set that wraps a database query or network communication.
* These would follow the same pattern (report the set as "stale", perform some
* slow operation, then make changes to the set).
* </p>
*
* @since 1.0
*/
public class AsynchronousTestSet extends ObservableSet<Object> {

private static Random randomNumberGenerator = new Random();

private final Display display;

private final boolean stale = false;

/**
* Average number of elements to add or remove
*/
private static final int AVERAGE_DELTA = 4;

/**
* Average "computation" time -- time taken to do the simulated work (ms)
*/
private static final int AVERAGE_BUSY_TIME = 1000;

/**
* List of all undisposed AsynchronousTestSet instances. Used for the
* recomputeAll method.
*/
private static List<Object> allSets = new ArrayList<>();

public AsynchronousTestSet() {
super(new HashSet<>(), Object.class);
display = Display.getCurrent();
if (display == null) {
throw new IllegalStateException(
"This object can only be created in the UI thread"); //$NON-NLS-1$
}
recompute();
}

@Override
protected void firstListenerAdded() {
super.firstListenerAdded();
allSets.add(this);
}

@Override
protected void lastListenerRemoved() {
allSets.remove(this);
super.lastListenerRemoved();
}

public static void recomputeAll() {
for (Object object : allSets) {
AsynchronousTestSet next = (AsynchronousTestSet) object;

next.recompute();
}
}

public void remove(Collection<Object> toRemove) {
Set<Object> removed = new HashSet<>();
removed.addAll(toRemove);
removed.retainAll(wrappedSet);

wrappedSet.removeAll(removed);
fireSetChange(Diffs.createSetDiff(Collections.emptySet(), removed));
}

@Override
public boolean isStale() {
return stale;
}

public void recompute() {
if (!isStale()) {
setStale(true);
final int sleepTime = (int) (randomNumberGenerator.nextDouble() * (AVERAGE_BUSY_TIME * 2));
Thread newThread = new Thread(() -> {

// Simulate work by sleeping
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
}

// Add and remove some elements -- important: fire all
// events in the UI thread
display.asyncExec(() -> {
final Set<Object> toAdd = new HashSet<>();
final Set<Object> toRemove = new HashSet<>();

// Compute elements to add and remove (basically
// just fills the toAdd
// and toRemove sets with random elements)
int delta = (randomNumberGenerator.nextInt(AVERAGE_DELTA * 4) - AVERAGE_DELTA * 2);
int extraAdds = randomNumberGenerator.nextInt(AVERAGE_DELTA);
int addCount = delta + extraAdds;
int removeCount = -delta + extraAdds;

if (addCount > 0) {
for (int i1 = 0; i1 < addCount; i1++) {
toAdd.add(Integer.valueOf(randomNumberGenerator.nextInt(20)));
}
}

if (removeCount > 0) {
Iterator<Object> oldElements = wrappedSet.iterator();
for (int i2 = 0; i2 < removeCount && oldElements.hasNext(); i2++) {
toRemove.add(oldElements.next());
}
}

toAdd.removeAll(wrappedSet);
wrappedSet.addAll(toAdd);
wrappedSet.removeAll(toRemove);

setStale(false);
fireSetChange(Diffs.createSetDiff(toAdd, toRemove));
});
});

newThread.start();
}
}
}
Loading

0 comments on commit 7f9199c

Please sign in to comment.