Java源码示例:org.openide.util.WeakListeners
示例1
public MinimizeModeAction() {
putValue(NAME, NbBundle.getMessage(CloseModeAction.class, "CTL_MinimizeModeAction"));
TopComponent.getRegistry().addPropertyChangeListener(
WeakListeners.propertyChange(this, TopComponent.getRegistry()));
WindowManager.getDefault().addPropertyChangeListener(
WeakListeners.propertyChange(this, WindowManager.getDefault()));
if (SwingUtilities.isEventDispatchThread()) {
updateEnabled();
} else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
updateEnabled();
}
});
}
}
示例2
/**
* Initialize the registry
* @param folder the name of the xml layer folder to use
* @param dataLookup the lookup to use when creating providers
*/
private void init(String folder, final Lookup dataLookup) {
Lookup lookup = Lookups.forPath(PATH + folder + NODEPROVIDERS);
lookupResult = lookup.lookupResult(NodeProviderFactory.class);
initProviders(dataLookup);
// listen for changes and re-init the providers when the lookup changes
lookupResult.addLookupListener(WeakListeners.create(LookupListener.class,
lookupListener = new LookupListener() {
@Override
public void resultChanged(LookupEvent ev) {
initProviders(dataLookup);
changeSupport.fireChange();
}
},
lookupResult)
);
}
示例3
/** Initialize this top component properly with information
* obtained from specified root context node */
private void initializeWithRootContext (Node rc) {
// update TC's attributes
setToolTipText(rc.getDisplayName());
setName(rc.getDisplayName());
updateTitle();
// attach listener
if (weakRcL == null) {
weakRcL = WeakListeners.propertyChange(
rcListener(), rc
);
}
rc.addPropertyChangeListener(weakRcL);
if (weakNRcL == null) {
weakNRcL = NodeOp.weakNodeListener (
rcListener(), rc
);
}
rc.addNodeListener(weakNRcL);
}
示例4
public MasterViewSupport(final Application application, ProfilingResultsSupport profilingResultsView,
CPUSettingsSupport cpuSettingsSupport, MemorySettingsSupport memorySettingsSupport,
JDBCSettingsSupport jdbcSettingsSupport, boolean classSharingBreaksProfiling) {
this.application = application;
this.profilingResultsView = profilingResultsView;
this.cpuSettingsSupport = cpuSettingsSupport;
this.memorySettingsSupport = memorySettingsSupport;
this.jdbcSettingsSupport = jdbcSettingsSupport;
this.classSharingBreaksProfiling = classSharingBreaksProfiling;
initComponents();
initSettings();
refreshStatus();
timer = new Timer(1000, this);
timer.setInitialDelay(1000);
NetBeansProfiler.getDefaultNB().addProfilingStateListener(this);
// TODO: should listen for PROPERTY_AVAILABLE instead of DataSource removal
application.notifyWhenRemoved(this);
application.addPropertyChangeListener(Stateful.PROPERTY_STATE, WeakListeners.propertyChange(this,application));
}
示例5
/**
* @param preprovider an initial context (may be null)
* @param providers a sequential list of property groups
*/
public SequentialPropertyEvaluator(final PropertyProvider preprovider, final PropertyProvider... providers) {
this.preprovider = preprovider;
this.providers = providers;
ProjectManager.mutex().readAccess(new Mutex.Action<Void>() {
public Void run() {
if (preprovider != null) {
predefs = copyAndCompact(preprovider.getProperties());
// XXX defer until someone is listening?
preprovider.addChangeListener(WeakListeners.change(SequentialPropertyEvaluator.this, preprovider));
} else {
predefs = Collections.emptyMap();
}
orderedDefs = new ArrayList<Map<String, String>>(providers.length);
for (PropertyProvider pp : providers) {
orderedDefs.add(copyAndCompact(pp.getProperties()));
pp.addChangeListener(WeakListeners.change(SequentialPropertyEvaluator.this, pp));
}
return null;
}
});
// XXX defer until someone asks for them?
defs = evaluateAll(predefs, orderedDefs);
}
示例6
public Result (
@NonNull final JavaPlatformManager jpm,
@NonNull final URL artifact,
@NonNull final Collection<? extends JavaPlatform> platforms) {
Parameters.notNull("jpm", jpm); //NOI18N
Parameters.notNull("artifact", artifact); //NOI18N
Parameters.notNull("platforms", platforms); //NOI18N
this.jpm = jpm;
this.artifact = artifact;
synchronized (this) {
this.platforms = new LinkedHashMap<>();
for (JavaPlatform platform : platforms) {
final PropertyChangeListener l = WeakListeners.propertyChange(this, platform);
platform.addPropertyChangeListener(l);
this.platforms.put(platform, l);
}
this.jpm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.jpm));
}
}
示例7
/**
* Set options that depend on current context, and listeners that ensure
* they stay valid when the context changes.
*/
private void setContextAwareOptions(boolean searchAndReplace) {
if (!searchAndReplace) {
updateSearchInGeneratedForActiveTopComponent();
topComponentRegistryListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(
TopComponent.Registry.PROP_ACTIVATED)) {
updateSearchInGeneratedForActiveTopComponent();
}
}
};
TopComponent.getRegistry().addPropertyChangeListener(
WeakListeners.propertyChange(topComponentRegistryListener,
TopComponent.getRegistry()));
}
}
示例8
/**
* Creates new form PortTypeOperationFaultPanel
*/
public PortTypeOperationFaultPanel(SectionView view, Fault fault){
super(view);
this.fault = fault;
this.model = this.fault.getModel();
initComponents();
disableEnterKey();
sync();
addModifier(javaClassText);
addModifier(defaultJavaClassCB);
addValidatee(javaClassText);
defaultListener = new DefaultItemListener();
ItemListener il = (ItemListener)WeakListeners.create(ItemListener.class, defaultListener,
defaultJavaClassCB);
defaultJavaClassCB.addItemListener(il);
}
示例9
public MissingNbInstallationProblemProvider(Project prj) {
pchs = new PropertyChangeSupport(this);
project = prj;
propertyListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (OpenProjects.PROPERTY_OPEN_PROJECTS.equals(evt.getPropertyName()) && OpenProjects.getDefault().isProjectOpen(project)) {
pchs.firePropertyChange(PROP_PROBLEMS, null, null);
}
if (NbMavenProject.PROP_PROJECT.equals(evt.getPropertyName())) {
pchs.firePropertyChange(PROP_PROBLEMS, null, null);
}
}
};
weak = WeakListeners.propertyChange(propertyListener, this);
}
示例10
private void addListener(PropertiesDataObject dataObj) {
PropertyChangeListener l =weakEnvPropListeners.get(dataObj);
VetoableChangeListener v = weakEnvVetoListeners.get(dataObj);
if (l != null) {
dataObj.removePropertyChangeListener(l);
} else {
l = WeakListeners.propertyChange(this, dataObj);
weakEnvPropListeners.put(dataObj, l);
}
if (v != null) {
dataObj.removeVetoableChangeListener(v);
} else {
v = WeakListeners.vetoableChange(this, dataObj);
weakEnvVetoListeners.put(dataObj, v);
}
dataObj.addPropertyChangeListener(l);
dataObj.addVetoableChangeListener(v);
}
示例11
/**
* Creates new form ActualSelectionProjectPanel
*/
public NodeSelectionProjectPanel() {
super(new BorderLayout());
JButton closeButton = CloseButtonFactory.createBigCloseButton();
prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, prefs));
closeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
prefs.putBoolean(KEY_ACTUALSELECTIONPROJECT, false);
}
});
add(closeButton, BorderLayout.EAST);
setBorder(new SeparatorBorder());
preferenceChange(null);
}
示例12
/** Creates a new instance of ExternalBindingTablePanel */
public ExternalBindingTablePanel(EBTableModel model, Node node) {
super(model);
getTable().getAccessibleContext().setAccessibleName(NbBundle.getMessage(ExternalBindingTablePanel.class,
"LBL_CUSTOMIZATION_FILES"));
getTable().getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ExternalBindingTablePanel.class,
"LBL_CUSTOMIZATION_FILES"));
this.model = model;
this.node = node;
this.editButton.setVisible(false); //can't edit an entry
addedBindings = new HashMap<String, FileObject>();
addActionListener = new AddActionListener();
ActionListener addListener = (ActionListener)WeakListeners.create(ActionListener.class,
addActionListener, addButton);
addButton.addActionListener(addListener);
removeActionListener = new RemoveActionListener();
ActionListener removeListener = (ActionListener)WeakListeners.create(ActionListener.class,
removeActionListener, removeButton);
removeButton.addActionListener(removeListener);
}
示例13
private void init(final Task task) {
if (!initialized) {
ClasspathInfo _tmpInfo = null;
if (task instanceof ClasspathInfo.Provider &&
(_tmpInfo = ((ClasspathInfo.Provider)task).getClasspathInfo()) != null) {
if (cpInfo != null && weakCpListener != null) {
cpInfo.removeChangeListener(weakCpListener);
this.weakCpListener = null;
}
cpInfo = _tmpInfo;
this.weakCpListener = WeakListeners.change(cpInfoListener, cpInfo);
cpInfo.addChangeListener (this.weakCpListener);
root = Optional.ofNullable(cpInfo.getClassPath(PathKind.SOURCE))
.map((cp)-> {
FileObject[] roots = cp.getRoots();
return roots.length > 0 ? roots[0] : null;
})
.orElse(null);
} else {
throw new IllegalArgumentException("No classpath provided by task: " + task);
}
initialized = true;
}
}
示例14
public GulpTasks getGulpTasks(@NullAllowed FileObject gulpfile) {
if (gulpfile == null
|| gulpfile.getParent().equals(project.getProjectDirectory())) {
return getProjectGulpTasks();
}
GulpTasks tasks = gulpTasks.get(gulpfile);
if (tasks != null) {
return tasks;
}
Gulpfile file = Gulpfile.create(gulpfile.getParent());
tasks = GulpTasks.create(project, file);
GulpTasks currentTasks = gulpTasks.putIfAbsent(gulpfile, tasks);
if (currentTasks != null) {
return currentTasks;
}
// register listener
file.addChangeListener(WeakListeners.change(cleanupListener, file));
return tasks;
}
示例15
/** Prepares settings. */
private void prepareSettings() {
if (prepared) return;
prepared = true;
// Set listening on changes of settings.
fontsColors = MimeLookup.getLookup(PropertiesKit.PROPERTIES_MIME_TYPE).lookupResult(FontColorSettings.class);
fontsColors.addLookupListener(WeakListeners.create(LookupListener.class, fontsColorsTracker, fontsColors));
keybindings = MimeLookup.getLookup(PropertiesKit.PROPERTIES_MIME_TYPE).lookupResult(KeyBindingSettings.class);
keybindings.addLookupListener(WeakListeners.create(LookupListener.class, keybindingsTracker, keybindings));
// Init settings.
updateColors();
updateKeyStrokes();
}
示例16
private void listenOnFrameworks() {
List<PhpFrameworkProvider> frameworks = project.getFrameworks();
List<ImportantFilesImplementation> newConfigFiles = new ArrayList<>(frameworks.size());
PhpModule phpModule = project.getPhpModule();
for (PhpFrameworkProvider framework : frameworks) {
ImportantFilesImplementation configurationFiles = framework.getConfigurationFiles2(phpModule);
if (configurationFiles != null) {
newConfigFiles.add(configurationFiles);
configurationFiles.addChangeListener(WeakListeners.change(this, configurationFiles));
} else {
File[] files = framework.getConfigurationFiles(phpModule);
if (files.length > 0) {
LOGGER.log(Level.INFO, "PHP framework {0} uses deprecated method, switch to PhpFrameworkProvider.getConfigurationFiles2()", framework.getIdentifier());
ImportantFilesImplementation dummyConfigFiles = new ImportantFilesImplementationImpl(project, framework.getIdentifier(), files);
newConfigFiles.add(dummyConfigFiles);
}
}
}
configFiles.clear();
configFiles.addAll(newConfigFiles);
}
示例17
@Messages({
"HpiPluginWarning_problem_displayName=Missing Hudson/Jenkins plugin support",
"HpiPluginWarning_problem_description=Hudson/Jenkins plugin development support was removed from NetBeans 7.3. Install https://github.com/stapler/netbeans-stapler-plugin (available from Plugin Portal).",
"HpiPluginWarning_unresolved=Automated installation from Plugin Portal not yet implemented; install the “Jenkins Plugin Support” and “Stapler Support” plugins."
})
@Override public Collection<? extends ProjectProblem> getProblems() {
for (ModuleInfo mi : modules.allInstances()) {
if (mi.getCodeNameBase().equals("org.kohsuke.stapler.netbeans.jenkinsdev")) {
if (mi.isEnabled()) {
return Collections.emptySet();
} else {
mi.addPropertyChangeListener(WeakListeners.propertyChange(this, mi));
// XXX better to display a specialized warning
continue;
}
}
}
return Collections.singleton(ProjectProblem.createWarning(HpiPluginWarning_problem_displayName(), HpiPluginWarning_problem_description(), new ProjectProblemResolverImpl()));
}
示例18
private EditorContextDispatcher() {
refreshProcessor = new RequestProcessor("Refresh Editor Context", 1); // NOI18N
resFileObject = Utilities.actionsGlobalContext().lookupResult(FileObject.class);
EditorLookupListener ell = new EditorLookupListener(FileObject.class);
resFileObject.addLookupListener(ell);
ell.lookupChanged(false); // To initialize data
erListener = new EditorRegistryListener();
EditorRegistry.addPropertyChangeListener(WeakListeners.propertyChange(erListener, EditorRegistry.class));
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// To initialize data:
((EditorRegistryListener) erListener).update(false);
}
});
}
示例19
/**
* Creates new form AndroidProjectSdkConfig
*/
public AndroidProjectSdkConfig(ProjectCustomizer.Category category, Lookup context) {
initComponents();
this.category = category;
androidProjectImpl = context.lookup(NbAndroidProject.class);
if (androidProjectImpl != null) {
sdk = androidProjectImpl.getLookup().lookup(AndroidSdk.class);
if (sdk != null) {
sdkList.setModel(new DefaultComboBoxModel(AndroidSdkProvider.getInstalledSDKs()));
sdkList.setSelectedItem(sdk);
AndroidSdkProvider.getDefault().addPropertyChangeListener(WeakListeners.propertyChange(this, AndroidSdkProvider.PROP_INSTALLED_SDKS, AndroidSdkProvider.getDefault()));
}
}
category.setStoreListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!sdkList.getSelectedItem().equals(sdk) && androidProjectImpl != null) {
androidProjectImpl.changeDefaultSdk((AndroidSdk) sdkList.getSelectedItem());
}
}
});
}
示例20
R(
@NonNull final URL url,
@NonNull final MultiModule modules,
@NonNull final String moduleName,
@NonNull final String[] templates) {
Parameters.notNull("url", url); //NOI18N
Parameters.notNull("modules", modules); //NOI18N
Parameters.notNull("moduleName", moduleName); //NOI18N
Parameters.notNull("templates", templates); //NOI18N
this.url = url;
this.pp = new EvaluatorPropertyProvider(MultiModuleBinaryForSourceQueryImpl.this.evaluator);
this.evaluator = PropertyUtils.sequentialPropertyEvaluator(
PropertyUtils.fixedPropertyProvider(Collections.singletonMap("module.name",moduleName)), //NOI18N
pp);
this.modules = modules;
this.moduleName = moduleName;
this.templates = templates;
this.cache = new AtomicReference();
this.listeners = new ChangeSupport(this);
this.propsCache = new AtomicReference<>();
this.scp = new AtomicReference<>();
MultiModuleBinaryForSourceQueryImpl.this.evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, MultiModuleBinaryForSourceQueryImpl.this.evaluator));
this.modules.addPropertyChangeListener(WeakListeners.propertyChange(this, this.modules));
}
示例21
/** Creates a new instance of the syntax coloring parser */
@Override
public Syntax createSyntax(Document doc) {
final Jsp11Syntax newSyntax = new Jsp11Syntax(new HtmlSyntax(), new JavaSyntax(null, true));
if(ATTACH_COLORING_LISTENER_TO_SYNTAX.get()) {
DataObject dobj = NbEditorUtilities.getDataObject(doc);
FileObject fobj = (dobj != null) ? dobj.getPrimaryFile() : null;
// tag library coloring data stuff
JspColoringData data = JspUtils.getJSPColoringData(fobj);
// construct the listener
PropertyChangeListener pList = new ColoringListener(doc, data, newSyntax);
// attach the listener
// PENDING - listen on the language
//jspdo.addPropertyChangeListener(WeakListeners.propertyChange(pList, jspdo));
if (data != null) {
data.addPropertyChangeListener(WeakListeners.propertyChange(pList, data));
}
}
return newSyntax;
}
示例22
/**
* constructor This method must be called by each child class to ensure that
* the lookups are properly initialised
*/
public MenuBaseAction() {
lookup = Utilities.actionsGlobalContext();
graphNodeSet = Utilities.actionsGlobalContext().lookupResult(GraphNode.class);
graphNodeSet.addLookupListener(
WeakListeners.create(LookupListener.class, this, graphNodeSet));
resultChanged(new LookupEvent(graphNodeSet));
}
示例23
/** Constructor that attaches itself to the filesystem pool.
*/
@SuppressWarnings("LeakingThisInConstructor")
private ClassLoaderSupport (final ClassPath cp, final ClassLoader parentClassLoader) {
super(getRootURLs(cp), parentClassLoader);
this.classPath = cp;
listener = FileUtil.weakFileChangeListener(this, null);
propListener = WeakListeners.propertyChange (this, null);
cp.addPropertyChangeListener(propListener);
}
示例24
@Override
protected void addNotify () {
SchemaElement el = getElement();
if (el != null) {
// listen to the source element property changes
if (wPropL == null) {
propL = new DBElementListener();
wPropL = WeakListeners.propertyChange(propL, el);
}
el.addPropertyChangeListener (wPropL);
}
refreshKeys ();
}
示例25
@SuppressWarnings("LeakingThisInConstructor")
public BootClassPathImpl(Project proj, boolean modulesOnly) {
super(proj);
this.modulesOnly = modulesOnly;
platformManager = JavaPlatformManager.getDefault();
platformManager.addPropertyChangeListener(WeakListeners.propertyChange(this, platformManager));
NbGradleProject.getPreferences(project, false).addPreferenceChangeListener(new PreferenceChangeListener() {
@Override
public void preferenceChange(PreferenceChangeEvent evt) {
if (RunUtils.PROP_JDK_PLATFORM.equals(evt.getKey())) {
clearResourceCache();
}
}
});
}
示例26
protected BooleanPreferenceKeyAction(String preferenceKey, boolean defaultValue) {
this.preferenceKey = preferenceKey;
this.defaultValue = defaultValue;
Preferences preferences = SnapApp.getDefault().getPreferences();
preferences.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, preferences));
setSelected(getPreferenceValue());
}
示例27
public J2eePlatformImplImpl(WLDeploymentManager dm) {
this.dm = dm;
moduleTypes.add(Type.WAR);
moduleTypes.add(Type.EJB);
moduleTypes.add(Type.EAR);
// Allow J2EE 1.4 Projects
profiles.add(Profile.J2EE_14);
// Check for WebLogic Server 10x to allow Java EE 5 Projects
Version version = dm.getDomainVersion();
if (version == null) {
version = dm.getServerVersion();
}
if (version != null) {
if (version.isAboveOrEqual(WLDeploymentFactory.VERSION_10)) {
profiles.add(Profile.JAVA_EE_5);
}
if (version.isAboveOrEqual(WLDeploymentFactory.VERSION_11)) {
profiles.add(Profile.JAVA_EE_6_FULL);
profiles.add(Profile.JAVA_EE_6_WEB);
}
if (version.isAboveOrEqual(WLDeploymentFactory.VERSION_1221)) {
profiles.add(Profile.JAVA_EE_7_FULL);
profiles.add(Profile.JAVA_EE_7_WEB);
}
}
domainChangeListener = new DomainChangeListener(this);
dm.addDomainChangeListener(WeakListeners.change(domainChangeListener, dm));
}
示例28
/**
* @param fo The file object to listen upon at DataObject level
* @param fcl The FileChangeListener to be called when the DataObject has been invalidated
*
* @throws org.openide.loaders.DataObjectNotFoundException
*/
public DataObjectListener(FileObject fo, FileChangeListener fcl) throws DataObjectNotFoundException {
this.fobj = fo;
this.flisten = fcl;
this.dobj = DataObject.find(fo);
wlistener = WeakListeners.propertyChange(this, dobj);
this.dobj.addPropertyChangeListener(wlistener);
}
示例29
public ParseErrorAnnotation(Severity severity, String customType, FixData fixes, String description, Position lineStart, AnnotationHolder holder) {
this.severity = severity;
this.customType = customType;
this.fixes = fixes;
this.description = description;
this.shortDescription = description + NbBundle.getMessage(ParseErrorAnnotation.class, "LBL_shortcut_promotion"); //NOI18N
this.lineStart = lineStart;
this.holder = holder;
if (!fixes.isComputed()) {
fixes.addPropertyChangeListener(WeakListeners.propertyChange(this, fixes));
}
}
示例30
private MultiModule(
@NonNull final SourceRoots moduleRoots,
@NonNull final SourceRoots srcRoots) {
Parameters.notNull("moduleRoots", moduleRoots); //NOI18N
Parameters.notNull("srcRoots", srcRoots); //NOI18N
this.moduleRoots = moduleRoots;
this.srcRoots = srcRoots;
this.cpCache = new AtomicReference<>(Collections.emptyMap());
this.mpCache = new AtomicReference<>();
this.listeners = new PropertyChangeSupport(this);
this.moduleRoots.addPropertyChangeListener(WeakListeners.propertyChange(this, this.moduleRoots));
this.srcRoots.addPropertyChangeListener(WeakListeners.propertyChange(this, this.srcRoots));
updateCache();
}