org.eclipse.jdt.internal.corext.fix.CleanUpPreferenceUtil Java Examples

The following examples show how to use org.eclipse.jdt.internal.corext.fix.CleanUpPreferenceUtil. 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: GWTJavaEditor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private boolean formatOnSaveEnabled(IJavaProject javaProject) {
  SaveParticipantRegistry spr = JavaPlugin.getDefault().getSaveParticipantRegistry();
  IPostSaveListener[] listeners = spr.getEnabledPostSaveListeners(javaProject.getProject());

  for (IPostSaveListener listener : listeners) {
    if (listener instanceof CleanUpPostSaveListener) {
      Map<String, String> settings =
          CleanUpPreferenceUtil.loadSaveParticipantOptions(new ProjectScope(
          javaProject.getProject()));

      if (settings == null) {
        return false;
      }

      return (CLEAN_UP_OPTION_TRUE.equals(settings.get(CleanUpConstants.FORMAT_SOURCE_CODE)));
    }
  }

  return false;
}
 
Example #2
Source File: CleanUpSaveParticipantPreferenceConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialize(final IScopeContext context, IAdaptable element) {
	fContext= context;
	fSettings= CleanUpPreferenceUtil.loadSaveParticipantOptions(context);

	settingsChanged();

	IJavaProject javaProject= null;
	if (element != null) {
		IProject project= (IProject)element.getAdapter(IProject.class);
		if (project != null) {
			IJavaProject jProject= JavaCore.create(project);
			if (jProject != null && jProject.exists()) {
				javaProject= jProject;
			}
		}
	}

	configurePreferenceLink(fFormatConfigLink, javaProject, CodeFormatterPreferencePage.PREF_ID, CodeFormatterPreferencePage.PROP_ID);
	configurePreferenceLink(fOrganizeImportsConfigLink, javaProject, ImportOrganizePreferencePage.PREF_ID, ImportOrganizePreferencePage.PROP_ID);

	super.initialize(context, element);
}
 
Example #3
Source File: CleanUpSaveParticipantPreferenceConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void performDefaults() {
	if (ProjectScope.SCOPE.equals(fContext.getName()) && !hasSettingsInScope(fContext))
		return;

	enabled(true);

	if (ProjectScope.SCOPE.equals(fContext.getName())) {
		fSettings= CleanUpPreferenceUtil.loadSaveParticipantOptions(InstanceScope.INSTANCE);
	} else {
		fSettings= JavaPlugin.getDefault().getCleanUpRegistry().getDefaultOptions(CleanUpConstants.DEFAULT_SAVE_ACTION_OPTIONS).getMap();
	}
	settingsChanged();

	super.performDefaults();
}
 
Example #4
Source File: CleanUpSaveParticipantPreferenceConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void performOk() {
	super.performOk();

	if (!ProjectScope.SCOPE.equals(fContext.getName()) || hasSettingsInScope(fContext))
		CleanUpPreferenceUtil.saveSaveParticipantOptions(fContext, fSettings);
}
 
Example #5
Source File: CleanUpSaveParticipantPreferenceConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void enableProjectSettings() {
	super.enableProjectSettings();

	CleanUpPreferenceUtil.saveSaveParticipantOptions(fContext, fSettings);
}
 
Example #6
Source File: CleanUpSaveParticipantPreferenceConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void disableProjectSettings() {
	super.disableProjectSettings();

	IEclipsePreferences node= fContext.getNode(JavaUI.ID_PLUGIN);

	Set<String> keys= JavaPlugin.getDefault().getCleanUpRegistry().getDefaultOptions(CleanUpConstants.DEFAULT_SAVE_ACTION_OPTIONS).getKeys();
	for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) {
		String key= iterator.next();
		node.remove(CleanUpPreferenceUtil.SAVE_PARTICIPANT_KEY_PREFIX + key);
	}
}
 
Example #7
Source File: CleanUpRefactoringWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Hashtable<String, Profile> loadProfiles() {
List<Profile> list= CleanUpPreferenceUtil.loadProfiles(InstanceScope.INSTANCE);
Hashtable<String, Profile> profileIdsTable= new Hashtable<String, Profile>();
for (Iterator<Profile> iterator= list.iterator(); iterator.hasNext();) {
       Profile profile= iterator.next();
       profileIdsTable.put(profile.getID(), profile);
      }

return profileIdsTable;
  }
 
Example #8
Source File: CompilationUnitEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Opens a warning dialog informing about a failure during handling of save listeners.
 *
 * @param title the dialog title
 * @param message the message to display
 * @param exception the exception to handle
 * @since 3.4
 */
private void openSaveListenerWarningDialog(String title, String message, CoreException exception) {
	final String linkText;
	final IJavaProject javaProject= getInputJavaElement().getJavaProject();
	IProject project= javaProject != null ? javaProject.getProject() : null;
	final boolean hasProjectSettings= project != null && CleanUpPreferenceUtil.hasSettingsInScope(new ProjectScope(project));
	if (exception.getStatus().getCode() == IJavaStatusConstants.EDITOR_POST_SAVE_NOTIFICATION) {
		message= JavaEditorMessages.CompilationUnitEditor_error_saving_participant_message;
		if (hasProjectSettings)
			linkText= JavaEditorMessages.CompilationUnitEditor_error_saving_participant_property_link;
		else
			linkText= JavaEditorMessages.CompilationUnitEditor_error_saving_participant_link;
	} else {
		message= JavaEditorMessages.CompilationUnitEditor_error_saving_editedLines_calculation_message;
		if (hasProjectSettings)
			linkText= JavaEditorMessages.CompilationUnitEditor_error_saving_editedLines_calculation_property_link;
		else
			linkText= JavaEditorMessages.CompilationUnitEditor_error_saving_editedLines_calculation_link;
	}

	IStatus status= exception.getStatus();
	int mask= IStatus.WARNING | IStatus.ERROR;
	ErrorDialog dialog= new ErrorDialog(getSite().getShell(), title, message, status, mask) {
		@Override
		protected Control createMessageArea(Composite parent) {
			Control result= super.createMessageArea(parent);

			// Panic code: use 'parent' instead of 'result' in case super implementation changes in the future
			new Label(parent, SWT.NONE);  // filler as parent has 2 columns (icon and label)
			Link link= new Link(parent, SWT.NONE);
			link.setText(linkText);
			link.setFont(parent.getFont());
			link.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					if (hasProjectSettings)
						PreferencesUtil.createPropertyDialogOn(getShell(), javaProject, SaveParticipantPreferencePage.PROPERTY_PAGE_ID, null, null).open();
					else
						PreferencesUtil.createPreferenceDialogOn(getShell(), SaveParticipantPreferencePage.PREFERENCE_PAGE_ID, null, null).open();
				}
			});
			GridData gridData= new GridData(SWT.FILL, SWT.BEGINNING, true, false);
			link.setLayoutData(gridData);

			return result;
		}
		@Override
		protected Image getImage() {
			return getWarningImage();
		}
	};
	dialog.open();
}
 
Example #9
Source File: CleanUpConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected ProfileManager createProfileManager(List<Profile> profiles, IScopeContext context, PreferencesAccess access, IProfileVersioner profileVersioner) {
	profiles.addAll(CleanUpPreferenceUtil.getBuiltInProfiles());
    fProfileManager= new CleanUpProfileManager(profiles, context, access, profileVersioner);
	return fProfileManager;
   }