use of org.eclipse.jface.util.IPropertyChangeListener in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method createControl.
@Override
public void createControl(Composite ancestor) {
setupActions();
fControl = new SashForm(ancestor, SWT.VERTICAL);
createTemplateTree(fControl);
createPatternForm(fControl);
hookContextMenu();
initializeDND();
updateButtons();
int sashSize = fPreferenceStore.getInt(SASH_SIZE_PREF_ID);
fControl.setWeights(new int[] { sashSize, 100 - sashSize });
fTemplateChangeListener = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
refresh();
}
});
}
};
getTemplatePreferenceStore().addPropertyChangeListener(fTemplateChangeListener);
updateContextTypes(getEditorContextTypeIds());
}
use of org.eclipse.jface.util.IPropertyChangeListener in project eclipse.platform.text by eclipse.
the class AnnotationColumn method initialize.
/**
* Initializes the given line number ruler column from the preference store.
*/
private void initialize() {
if (fDelegate == null)
fDelegate = new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, new DefaultMarkerAnnotationAccess());
IPreferenceStore store = getPreferenceStore();
if (store != null && fDelegate instanceof AnnotationRulerColumn) {
final AnnotationRulerColumn column = (AnnotationRulerColumn) fDelegate;
// initial set up
for (Iterator<AnnotationPreference> iter2 = fAnnotationPreferences.getAnnotationPreferences().iterator(); iter2.hasNext(); ) {
AnnotationPreference preference = iter2.next();
String key = preference.getVerticalRulerPreferenceKey();
boolean showAnnotation = true;
if (key != null && store.contains(key))
showAnnotation = store.getBoolean(key);
if (showAnnotation)
column.addAnnotationType(preference.getAnnotationType());
}
column.addAnnotationType(Annotation.TYPE_UNKNOWN);
// link to preference store
fPropertyListener = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
AnnotationPreference annotationPreference = getVerticalRulerAnnotationPreference(property);
if (annotationPreference != null && property.equals(annotationPreference.getVerticalRulerPreferenceKey())) {
Object type = annotationPreference.getAnnotationType();
if (getPreferenceStore().getBoolean(property))
column.addAnnotationType(type);
else
column.removeAnnotationType(type);
column.redraw();
}
}
};
store.addPropertyChangeListener(fPropertyListener);
}
}
use of org.eclipse.jface.util.IPropertyChangeListener in project eclipse.platform.text by eclipse.
the class PropagatingFontFieldEditor method startPropagate.
/**
* Starts the propagation of the font preference stored in the source preference
* store under the source key to the target preference store using the target
* preference key.
*
* @param source the source preference store
* @param sourceKey the key to be used in the source preference store
* @param target the target preference store
* @param targetKey the key to be used in the target preference store
*/
public static void startPropagate(final IPreferenceStore source, final String sourceKey, final IPreferenceStore target, final String targetKey) {
source.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (sourceKey.equals(event.getProperty()))
propagateFont(source, sourceKey, target, targetKey);
}
});
propagateFont(source, sourceKey, target, targetKey);
}
use of org.eclipse.jface.util.IPropertyChangeListener in project knime-core by knime.
the class KNIMECorePlugin method start.
/**
* This method is called upon plug-in activation.
*
* @param context The OSGI bundle context
* @throws Exception If this plugin could not be started
*/
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
if (!Boolean.getBoolean("java.awt.headless") && (Display.getCurrent() != null)) {
getImageRegistry();
}
try {
// get the preference store
// with the preferences for nr threads and tempDir
IPreferenceStore pStore = KNIMECorePlugin.getDefault().getPreferenceStore();
initMaxThreadCountProperty();
initTmpDirProperty();
// set log file level to stored
String logLevelFile = pStore.getString(HeadlessPreferencesConstants.P_LOGLEVEL_LOG_FILE);
NodeLogger.setAppenderLevelRange(NodeLogger.LOGFILE_APPENDER, LEVEL.valueOf(logLevelFile), LEVEL.FATAL);
final boolean enableWorkflowRelativeLogging = pStore.getBoolean(HeadlessPreferencesConstants.P_LOG_FILE_LOCATION);
NodeLogger.logInWorkflowDir(enableWorkflowRelativeLogging);
final boolean enableGlobalInWfLogging = pStore.getBoolean(HeadlessPreferencesConstants.P_LOG_GLOBAL_IN_WF_DIR);
NodeLogger.logGlobalMsgsInWfDir(enableGlobalInWfLogging);
pStore.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
if (event.getProperty().equals(HeadlessPreferencesConstants.P_MAXIMUM_THREADS)) {
if (!(event.getNewValue() instanceof Integer)) {
// not set, they send an empty string
return;
}
int count;
try {
count = (Integer) event.getNewValue();
KNIMEConstants.GLOBAL_THREAD_POOL.setMaxThreads(count);
} catch (Exception e) {
LOGGER.error("Unable to get maximum thread count " + " from preference page.", e);
}
} else if (event.getProperty().equals(HeadlessPreferencesConstants.P_TEMP_DIR)) {
if (!(event.getNewValue() instanceof String)) {
// not set, they send an empty string
return;
}
String dirName = (String) event.getNewValue();
if (dirName.isEmpty()) {
return;
}
File f = new File(dirName);
LOGGER.debug("Setting temp dir to " + f.getAbsolutePath());
try {
KNIMEConstants.setKNIMETempDir(f);
} catch (Exception e) {
LOGGER.error("Setting temp dir failed: " + e.getMessage(), e);
}
} else if (event.getProperty().equals(HeadlessPreferencesConstants.P_LOGLEVEL_LOG_FILE)) {
if (!(event.getNewValue() instanceof String)) {
// not set, they send an empty string
return;
}
String newName = (String) event.getNewValue();
if (newName.isEmpty()) {
return;
}
LEVEL level = LEVEL.WARN;
try {
level = LEVEL.valueOf(newName);
} catch (IllegalArgumentException iae) {
LOGGER.error("Invalid log level " + newName + ", using WARN");
}
NodeLogger.setAppenderLevelRange(NodeLogger.LOGFILE_APPENDER, level, LEVEL.FATAL);
} else if (event.getProperty().equals(HeadlessPreferencesConstants.P_LOG_FILE_LOCATION)) {
if (!(event.getNewValue() instanceof Boolean)) {
// when preferences are imported and this value is not set, they send an empty string
return;
}
Boolean enable = (Boolean) event.getNewValue();
NodeLogger.logInWorkflowDir(enable);
} else if (event.getProperty().equals(HeadlessPreferencesConstants.P_LOG_GLOBAL_IN_WF_DIR)) {
if (!(event.getNewValue() instanceof Boolean)) {
// when preferences are imported and this value is not set, they send an empty string
return;
}
Boolean enable = (Boolean) event.getNewValue();
NodeLogger.logGlobalMsgsInWfDir(enable);
} else if (P_LOGLEVEL_CONSOLE.equals(event.getProperty())) {
if (!(event.getNewValue() instanceof String)) {
// not set, they send an empty string
return;
}
String newName = (String) event.getNewValue();
if (newName.isEmpty()) {
return;
}
setLogLevel(newName);
} else if (HeadlessPreferencesConstants.P_DATABASE_DRIVERS.equals(event.getProperty())) {
String dbDrivers = (String) event.getNewValue();
initDatabaseDriver(dbDrivers);
} else if (HeadlessPreferencesConstants.P_DATABASE_TIMEOUT.equals(event.getProperty())) {
DatabaseConnectionSettings.setDatabaseTimeout(Integer.parseInt(event.getNewValue().toString()));
}
}
});
// end property listener
String logLevelConsole = pStore.getString(P_LOGLEVEL_CONSOLE);
if (!Boolean.getBoolean("java.awt.headless") && PlatformUI.isWorkbenchRunning()) {
try {
ConsoleViewAppender.FORCED_APPENDER.write(KNIMEConstants.WELCOME_MESSAGE);
ConsoleViewAppender.INFO_APPENDER.write("Log file is located at: " + KNIMEConstants.getKNIMEHomeDir() + File.separator + NodeLogger.LOG_FILE + "\n");
} catch (IOException ioe) {
LOGGER.error("Could not print welcome message: ", ioe);
}
setLogLevel(logLevelConsole);
}
// encryption key supplier registered with the eclipse framework
// and serves as a master key provider
KnimeEncryption.setEncryptionKeySupplier(new EclipseEncryptionKeySupplier());
// load database driver files from core preference page
String dbDrivers = pStore.getString(HeadlessPreferencesConstants.P_DATABASE_DRIVERS);
initDatabaseDriver(dbDrivers);
DatabaseConnectionSettings.setDatabaseTimeout(pStore.getInt(HeadlessPreferencesConstants.P_DATABASE_TIMEOUT));
} catch (Throwable e) {
LOGGER.error("Error while starting workbench, some setting may not have been applied properly: " + e.getMessage(), e);
}
}
use of org.eclipse.jface.util.IPropertyChangeListener in project knime-core by knime.
the class KNIMEUIPlugin method start.
/**
* This method is called upon plug-in activation.
*
* @param context The bundle context
* @throws Exception If failed
*/
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
// create a knime encryption supplier that reads in an encryption key
// from the user via a dialog or directly from the preference page
KnimeEncryption.setEncryptionKeySupplier(MasterKeyPreferencePage.SUPPLIER);
if (Display.getCurrent() != null) {
// do not load UI stuff if we run, e.g. the batch executor
getImageRegistry().put("knime", imageDescriptorFromPlugin(PLUGIN_ID, "/icons/knime_default.png"));
}
IPreferenceStore prefStore = getPreferenceStore();
int freqHistorySize = prefStore.getInt(PreferenceConstants.P_FAV_FREQUENCY_HISTORY_SIZE);
int usedHistorySize = prefStore.getInt(PreferenceConstants.P_FAV_LAST_USED_SIZE);
boolean wrapColumnHeaderInTable = prefStore.getBoolean(PreferenceConstants.P_WRAP_TABLE_HEADER);
prefStore.addPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent event) {
String prop = event.getProperty();
if (PreferenceConstants.P_FAV_FREQUENCY_HISTORY_SIZE.equals(prop)) {
if (!(event.getNewValue() instanceof Integer)) {
// not set, they send an empty string
return;
}
int count;
try {
count = (Integer) event.getNewValue();
NodeUsageRegistry.setMaxFrequentSize(count);
} catch (Exception e) {
LOGGER.error("Unable to set maximum number of " + "frequently used nodes", e);
}
} else if (PreferenceConstants.P_FAV_LAST_USED_SIZE.equals(prop)) {
if (!(event.getNewValue() instanceof Integer)) {
// not set, they send an empty string
return;
}
int count;
try {
count = (Integer) event.getNewValue();
NodeUsageRegistry.setMaxLastUsedSize(count);
} catch (Exception e) {
LOGGER.error("Unable to set maximum number of " + "last used nodes", e);
}
} else if (PreferenceConstants.P_WRAP_TABLE_HEADER.equals(prop) && (event.getNewValue() instanceof Boolean)) {
CorePlugin.getInstance().setWrapColumnHeaderInTableViews((Boolean) event.getNewValue());
}
}
});
try {
NodeUsageRegistry.setMaxFrequentSize(freqHistorySize);
NodeUsageRegistry.setMaxLastUsedSize(usedHistorySize);
} catch (Exception e) {
LOGGER.error("Error during loading of node usage history: ", e);
}
CorePlugin.getInstance().setWrapColumnHeaderInTableViews(wrapColumnHeaderInTable);
// hide already installed IU by default in install wizard
// its a bit dirty but there is no API to set the option
// the constants are taken from AvailableIUsPage
IDialogSettings ds = ProvUIActivator.getDefault().getDialogSettings();
IDialogSettings ds2 = ds.getSection("AvailableIUsPage");
if (ds2 == null) {
ds2 = ds.addNewSection("AvailableIUsPage");
ds2.put("HideInstalledContent", true);
} else if (ds2.get("HideInstalledContent") == null) {
ds2.put("HideInstalledContent", true);
}
}
Aggregations