org.eclipse.jface.preference.IPersistentPreferenceStore Java Examples

The following examples show how to use org.eclipse.jface.preference.IPersistentPreferenceStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractN4JSPreferencePage.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean performOk() {
	IWorkbenchPreferenceContainer container = (IWorkbenchPreferenceContainer) getContainer();
	if (!processChanges(container)) {
		return false;
	}
	boolean retVal = super.performOk();

	if (retVal && isProjectPreferencePage()) {
		try {
			IPreferenceStore preferenceStore = preferenceStoreAccessImpl.getWritablePreferenceStore(getProject());
			if (preferenceStore instanceof IPersistentPreferenceStore) {
				((IPersistentPreferenceStore) preferenceStore).save();
			}
		} catch (Exception e) {
			System.err.println(e);
			retVal = false;
		}
	}
	return retVal;
}
 
Example #2
Source File: SetLayoutAction.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
    PromptOverlay overlay = promptOverlay.get();
    if (overlay == null || preferences == null) {
        return;
    }
    Integer newSize = DialogHelpers.openAskInt("Percentual size for console prompt.",
            "Please enter the relative size for the console prompt (0-100)",
            preferences.getInt(PydevDebugPreferencesInitializer.RELATIVE_CONSOLE_HEIGHT));
    if (newSize != null) {
        if (newSize < 0) {
            newSize = 0;
        }
        if (newSize > 100) {
            newSize = 100;
        }
    }
    preferences.setValue(PydevDebugPreferencesInitializer.RELATIVE_CONSOLE_HEIGHT, newSize);
    if (preferences instanceof IPersistentPreferenceStore) {
        try {
            ((IPersistentPreferenceStore) preferences).save();
        } catch (IOException e) {
            Log.log(e);
        }
    }
}
 
Example #3
Source File: AbstractToggleActionContributor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void toggle() {
	boolean newState = !isPropertySet();
	IPreferenceStore store = preferenceStoreAccess.getWritablePreferenceStore();
	store.setValue(getPreferenceKey(), newState);
	if (store instanceof IPersistentPreferenceStore) {
		try {
			((IPersistentPreferenceStore) store).save();
		} catch (IOException e) {
			// log and ignore
			logger.debug(e.getMessage(), e);
		}
	}
	// Prevent sending state change event twice, already called by the propertyChangeListener
	if (propertyChangeListener == null)
		stateChanged(newState);
}
 
Example #4
Source File: UpdateCheck.java    From cppcheclipse with Apache License 2.0 6 votes vote down vote up
private static boolean needUpdateCheck() {
	IPersistentPreferenceStore configuration = CppcheclipsePlugin
			.getConfigurationPreferenceStore();
	if (!configuration
			.getBoolean(IPreferenceConstants.P_USE_AUTOMATIC_UPDATE_CHECK)) {
		return false;
	}

	Date lastUpdateDate = getLastUpdateCheckDate();
	if (lastUpdateDate == null) {
		return true;
	}

	Date today = new Date();

	long timeDifferenceMS = today.getTime() - lastUpdateDate.getTime();
	String updateInterval = configuration
			.getString(IPreferenceConstants.P_AUTOMATIC_UPDATE_CHECK_INTERVAL);
	for (int i = 0; i < INTERVALS.length; i++) {
		if (updateInterval.equals(INTERVALS[i][1])) {
			return timeDifferenceMS >= INTERVALS_IN_MS[i];
		}
	}
	return false;
}
 
Example #5
Source File: UpdateCheck.java    From cppcheclipse with Apache License 2.0 6 votes vote down vote up
public static Date getLastUpdateCheckDate() {
	IPersistentPreferenceStore configuration = CppcheclipsePlugin
			.getConfigurationPreferenceStore();

	String dateString = configuration
			.getString(IPreferenceConstants.P_LAST_UPDATE_CHECK);
	if (dateString.length() == 0) {
		return null;
	}

	DateFormat format = new SimpleDateFormat(DATE_PATTERN);
	Date lastUpdateDate = null;
	try {
		lastUpdateDate = format.parse(dateString);
	} catch (ParseException e) {
		CppcheclipsePlugin.logError("Could not parse date from last update check", e);
	}
	return lastUpdateDate;
}
 
Example #6
Source File: SetBufferedOutputAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void savePrefs() {
    if (preferences instanceof IPersistentPreferenceStore) {
        try {
            ((IPersistentPreferenceStore) preferences).save();
        } catch (IOException e) {
            Log.log(e);
        }
    }

}
 
Example #7
Source File: DartPreferencePage.java    From dartboard with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Saves the underlying {@link IPersistentPreferenceStore}.
 *
 * @throws IOException
 */
private void save() throws IOException {
	IPreferenceStore store = getPreferenceStore();
	if (store instanceof IPersistentPreferenceStore) {
		((IPersistentPreferenceStore) store).save();
	}
}
 
Example #8
Source File: SetFullLayoutAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
    PromptOverlay overlay = promptOverlay.get();
    if (overlay == null || preferences == null) {
        return;
    }
    int relativeConsoleHeight = overlay.getRelativeConsoleHeight();
    int newSize;
    if (relativeConsoleHeight < 100) {
        previousConsoleHeight = relativeConsoleHeight;
        newSize = 100;
        preferences.setValue(PydevDebugPreferencesInitializer.CONSOLE_PROMPT_OUTPUT_MODE,
                PydevDebugPreferencesInitializer.MODE_NOT_ASYNC_SAME_CONSOLE);
    } else {
        newSize = previousConsoleHeight;
        preferences.setValue(PydevDebugPreferencesInitializer.CONSOLE_PROMPT_OUTPUT_MODE,
                PydevDebugPreferencesInitializer.MODE_ASYNC_SEPARATE_CONSOLE);
    }
    preferences.setValue(PydevDebugPreferencesInitializer.RELATIVE_CONSOLE_HEIGHT, newSize);
    if (preferences instanceof IPersistentPreferenceStore) {
        try {
            ((IPersistentPreferenceStore) preferences).save();
        } catch (IOException e) {
            Log.log(e);
        }
    }
    updateText();
}
 
Example #9
Source File: ShowPromptOverlayAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(IAction action) {
    preferences.setValue(PydevDebugPreferencesInitializer.SHOW_CONSOLE_PROMPT_ON_DEBUG,
            !preferences.getBoolean(PydevDebugPreferencesInitializer.SHOW_CONSOLE_PROMPT_ON_DEBUG));

    if (preferences instanceof IPersistentPreferenceStore) {
        try {
            ((IPersistentPreferenceStore) preferences).save();
        } catch (IOException e) {
            Log.log(e);
        }
    }
}
 
Example #10
Source File: ScopedFieldEditorPreferencePage.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean performOk() {
    boolean ret = super.performOk();
    IPreferenceStore preferenceStore2 = getPreferenceStore();
    // When the user presses apply, make sure we try to persist now, not when the IDE is closed.
    if (preferenceStore2 instanceof IPersistentPreferenceStore) {
        IPersistentPreferenceStore iPersistentPreferenceStore = (IPersistentPreferenceStore) preferenceStore2;
        try {
            iPersistentPreferenceStore.save();
        } catch (IOException e) {
            Log.log(e);
        }
    }
    return ret;
}
 
Example #11
Source File: PreferenceWrapper.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void save( ) throws IOException
{
	if ( this.preferenceType == SPECIAL_TYPE && project != null )
		prefs.saveReportPreference( project );
	else if ( prefsStore instanceof IPersistentPreferenceStore )
		( (IPersistentPreferenceStore) prefsStore ).save( );

}
 
Example #12
Source File: Store.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
public void save() {
    if (store.needsSaving() && store instanceof IPersistentPreferenceStore) {
        try {
            ((IPersistentPreferenceStore)store).save();
        } catch (IOException e) {
            Activator.logError(Activator.getResourceString("easyshell.message.error.store.save"), e);
        }
    }
}
 
Example #13
Source File: UpdateCheck.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
@Override
protected IStatus run(IProgressMonitor monitor) {
	monitor.beginTask(getName(), 1);
	if (monitor.isCanceled())
		return Status.CANCEL_STATUS;

	UpdateCheckCommand updateCheck = new UpdateCheckCommand();
	Version newVersion;
	try {
		newVersion = updateCheck.run(monitor, Console.getInstance(), binaryPath);
		DateFormat format = new SimpleDateFormat(DATE_PATTERN);
		IPersistentPreferenceStore configuration = CppcheclipsePlugin
				.getConfigurationPreferenceStore();
		configuration.setValue(
				IPreferenceConstants.P_LAST_UPDATE_CHECK, format
						.format(new Date()));
		configuration.save();
		Display display = Display.getDefault();
		display.syncExec(new UpdateCheckNotifier(newVersion));
	} catch (Exception e) {
		if (!isSilent) {
			CppcheclipsePlugin
					.showError("Error checking for update", e); //$NON-NLS-1$
		} else {
			CppcheclipsePlugin.logError("Error checking for update", e);
		}
	}
	return Status.OK_STATUS;
}
 
Example #14
Source File: Symbols.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
public void save() throws IOException {
	StringBuffer symbolsSerialization = new StringBuffer();
	for (Symbol symbol : symbols) {
		// only serialize user-defined symbols
		if (!symbol.isCDTDefined())
			symbolsSerialization.append(symbol.serialize()).append(DELIMITER);
	}

	projectPreferences.setValue(IPreferenceConstants.P_SYMBOLS,
			symbolsSerialization.toString());

	if (projectPreferences instanceof IPersistentPreferenceStore) {
		((IPersistentPreferenceStore) projectPreferences).save();
	}
}
 
Example #15
Source File: SuppressionProfile.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
public void save() throws IOException {
	StringBuffer suppressions = new StringBuffer();
	for (Suppression suppression : suppressionList) {
		suppressions.append(suppression.serialize()).append(DELIMITER);
	}

	projectPreferences.setValue(IPreferenceConstants.P_SUPPRESSIONS,
			suppressions.toString());

	if (projectPreferences instanceof IPersistentPreferenceStore) {
		((IPersistentPreferenceStore) projectPreferences).save();
	}
}
 
Example #16
Source File: CppcheclipsePlugin.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
public static IPersistentPreferenceStore getProjectPreferenceStore(IProject project) {
	// Create an overlay preference store and fill it with properties
	ProjectScope ps = new ProjectScope(project);
	ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, getId());
	PreferenceInitializer.initializePropertiesDefault(scoped);
	return scoped;
}
 
Example #17
Source File: OptionsConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void savePreferences() {
	try {
		if (preferenceStore instanceof IPersistentPreferenceStore) {
			((IPersistentPreferenceStore) preferenceStore).save();
		}
	} catch (IOException e) {
		logError("Unexpected internal error: ", e); //$NON-NLS-1$
	}
}
 
Example #18
Source File: AreaBasedPreferencePage.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Override
public boolean performOk() {
  for (PreferenceArea area : areas) {
    area.performApply();
    if (area.getPreferenceStore() instanceof IPersistentPreferenceStore) {
      try {
        ((IPersistentPreferenceStore) area.getPreferenceStore()).save();
      } catch (IOException ex) {
        logger.log(Level.SEVERE, "Unable to persist preferences for " + area, ex);
        return false;
      }
    }
  }
  return true;
}
 
Example #19
Source File: AbstractN4JSPreferencePage.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * If the preference store is persistable, it will serialized here.
 *
 * This method has been copied and adapted from org.eclipse.xtext.ui.preferences.OptionsConfigurationBlock.
 */
protected void savePreferences() {
	try {
		if (getPreferenceStore() instanceof IPersistentPreferenceStore) {
			((IPersistentPreferenceStore) getPreferenceStore()).save();
		}
	} catch (IOException e) {
		IStatus status = new Status(IStatus.ERROR, N4JSActivator.getInstance().getBundle().getSymbolicName(),
				"Unexpected internal error: ", e); //$NON-NLS-1$
		N4JSActivator.getInstance().getLog().log(status);
	}
}
 
Example #20
Source File: CppcheclipsePlugin.java    From cppcheclipse with Apache License 2.0 4 votes vote down vote up
public static IPersistentPreferenceStore getConfigurationPreferenceStore() {
	return getDefault().getInternalConfigurationPreferenceStore();
}
 
Example #21
Source File: CppcheclipsePlugin.java    From cppcheclipse with Apache License 2.0 4 votes vote down vote up
public static IPersistentPreferenceStore getWorkspacePreferenceStore() {
	return getDefault().getInternalWorkspacePreferenceStore();
}
 
Example #22
Source File: UpdateCheck.java    From cppcheclipse with Apache License 2.0 4 votes vote down vote up
public void run() {
	Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
			.getShell();
	// if no new version found, just display a dialog if not in silent mode
	if (newVersion == null) {
		if (!isSilent) {
			MessageDialog.openInformation(shell,
					Messages.UpdateCheck_NoUpdateTitle,
					Messages.UpdateCheck_NoUpdateMessage);
		}
	} else {
		boolean downloadUpdate = false;
		// only have toggle switch for update check if silent (not
		// started from preferences)
		if (isSilent) {
			MessageDialogWithToggle msgDialog = MessageDialogWithToggle
					.openYesNoQuestion(shell,
							Messages.UpdateCheck_UpdateTitle,
							Messages.bind(
									Messages.UpdateCheck_UpdateMessage,
									newVersion),
							Messages.UpdateCheck_NeverCheckAgain,
							false, null, null);
			IPersistentPreferenceStore configuration = CppcheclipsePlugin
					.getConfigurationPreferenceStore();
			configuration.setValue(
					IPreferenceConstants.P_USE_AUTOMATIC_UPDATE_CHECK,
					!msgDialog.getToggleState());
			if (msgDialog.getReturnCode() == IDialogConstants.YES_ID) {
				downloadUpdate = true;
			}
			try {
				configuration.save();
			} catch (IOException e1) {
				CppcheclipsePlugin.logError("Could not save changes for update checks", e1);
			}
		} else {
			downloadUpdate = MessageDialog.openQuestion(shell,
					Messages.UpdateCheck_UpdateTitle, Messages.bind(
							Messages.UpdateCheck_UpdateMessage,
							newVersion));
		}

		if (downloadUpdate) {
			try {
				Utils.openUrl(DOWNLOAD_URL);
			} catch (Exception e) {
				CppcheclipsePlugin.logError("Could not open cppcheck download page", e);
			}
		}
	}
}
 
Example #23
Source File: QuickfixTestBuilder.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
private IPersistentPreferenceStore getPreferenceStore() {
  IPreferenceStore _writablePreferenceStore = this.preferenceStoreAccess.getWritablePreferenceStore(this._workbenchTestHelper.getProject());
  return ((IPersistentPreferenceStore) _writablePreferenceStore);
}
 
Example #24
Source File: XtendUIValidationTests.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public IPersistentPreferenceStore getXtendPreferencesStore() {
  IPreferenceStore _writablePreferenceStore = this.prefStoreAccess.getWritablePreferenceStore(this.testHelper.getProject());
  return ((IPersistentPreferenceStore) _writablePreferenceStore);
}
 
Example #25
Source File: AreaPreferencePageTest.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
public TestPrefArea(String preferenceName, String preferenceValue,
    IPersistentPreferenceStore preferences) {
  this.preferenceName = preferenceName;
  this.preferenceValue = preferenceValue;
  setPreferenceStore(preferences);
}