use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class CheckConfigurationWorkingSetEditor method exportCheckstyleCheckConfig.
/**
* Export a configuration.
*/
private void exportCheckstyleCheckConfig() {
IStructuredSelection selection = (IStructuredSelection) mViewer.getSelection();
ICheckConfiguration config = (ICheckConfiguration) selection.getFirstElement();
if (config == null) {
//
return;
}
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
dialog.setText(Messages.CheckstylePreferencePage_titleExportConfig);
String path = dialog.open();
if (path == null) {
return;
}
File file = new File(path);
try {
CheckConfigurationFactory.exportConfiguration(file, config);
} catch (CheckstylePluginException e) {
CheckstyleUIPlugin.errorDialog(getShell(), Messages.msgErrorFailedExportConfig, e, true);
}
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class RuleConfigurationEditDialog method okPressed.
/**
* OK button was selected.
*/
@Override
protected void okPressed() {
//
// Get the selected severity level.
//
Severity severity = mRule.getSeverity();
try {
severity = (Severity) ((IStructuredSelection) mSeverityCombo.getSelection()).getFirstElement();
} catch (IllegalArgumentException e) {
CheckstyleLog.log(e);
}
// Get the comment.
final String comment = Strings.emptyToNull(mCommentText.getText());
// Get the id
final String id = Strings.emptyToNull(mIdText.getText());
// Get the custom message
for (Map.Entry<String, Text> entry : mCustomMessages.entrySet()) {
String msgKey = entry.getKey();
String standardMessage = MetadataFactory.getStandardMessage(msgKey, mRule.getMetaData().getInternalName());
if (standardMessage == null) {
// $NON-NLS-1$
standardMessage = "";
}
String message = Strings.emptyToNull(entry.getValue().getText());
if (message != null && !message.equals(standardMessage)) {
mRule.getCustomMessages().put(msgKey, message);
} else {
mRule.getCustomMessages().remove(msgKey);
}
}
//
if (mConfigPropertyWidgets != null) {
for (int i = 0; i < mConfigPropertyWidgets.length; i++) {
IConfigPropertyWidget widget = mConfigPropertyWidgets[i];
ConfigProperty property = widget.getConfigProperty();
try {
widget.validate();
} catch (CheckstylePluginException e) {
String message = NLS.bind(Messages.RuleConfigurationEditDialog_msgInvalidPropertyValue, property.getMetaData().getName());
this.setErrorMessage(message);
return;
}
property.setValue(widget.getValue());
}
}
//
// If we made it this far then all of the user input validated and we
// can
// update the final rule with the values the user entered.
//
mRule.setSeverity(severity);
mRule.setComment(comment);
mRule.setId(id);
super.okPressed();
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class CheckstylePropertyPage method setElement.
/**
* {@inheritDoc}
*/
@Override
public void setElement(IAdaptable element) {
super.setElement(element);
IProject project = null;
try {
//
// Get the project.
//
IResource resource = (IResource) element;
if (resource.getType() == IResource.PROJECT) {
project = (IProject) resource;
}
IProjectConfiguration projectConfig = ProjectConfigurationFactory.getConfiguration(project);
mProjectConfig = new ProjectConfigurationWorkingCopy(projectConfig);
mCheckstyleInitiallyActivated = project.hasNature(CheckstyleNature.NATURE_ID);
} catch (CoreException e) {
handleConfigFileError(e, project);
} catch (CheckstylePluginException e) {
handleConfigFileError(e, project);
}
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class CheckstylePropertyPage method performOk.
@Override
public boolean performOk() {
try {
IProject project = mProjectConfig.getProject();
// save the edited project configuration
if (mProjectConfig.isDirty()) {
mProjectConfig.store();
}
boolean checkstyleEnabled = mChkEnable.getSelection();
boolean needRebuild = mProjectConfig.isRebuildNeeded();
// check if checkstyle nature has to be configured/deconfigured
if (checkstyleEnabled != mCheckstyleInitiallyActivated) {
ConfigureDeconfigureNatureJob configOperation = new ConfigureDeconfigureNatureJob(project, CheckstyleNature.NATURE_ID);
configOperation.setRule(ResourcesPlugin.getWorkspace().getRoot());
configOperation.schedule();
needRebuild = needRebuild || !mCheckstyleInitiallyActivated;
}
if (checkstyleEnabled && mProjectConfig.isSyncFormatter()) {
TransformCheckstyleRulesJob transFormJob = new TransformCheckstyleRulesJob(project);
transFormJob.schedule();
}
// really be done.
if (checkstyleEnabled && needRebuild) {
String promptRebuildPref = CheckstyleUIPluginPrefs.getString(CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);
boolean doRebuild = MessageDialogWithToggle.ALWAYS.equals(promptRebuildPref) && needRebuild;
//
if (MessageDialogWithToggle.PROMPT.equals(promptRebuildPref) && needRebuild) {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getShell(), Messages.CheckstylePropertyPage_titleRebuild, Messages.CheckstylePropertyPage_msgRebuild, Messages.CheckstylePropertyPage_nagRebuild, false, CheckstyleUIPlugin.getDefault().getPreferenceStore(), CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);
doRebuild = dialog.getReturnCode() == IDialogConstants.YES_ID;
}
// check if a rebuild is necessary
if (checkstyleEnabled && doRebuild) {
BuildProjectJob rebuildOperation = new BuildProjectJob(project, IncrementalProjectBuilder.FULL_BUILD);
rebuildOperation.setRule(ResourcesPlugin.getWorkspace().getRoot());
rebuildOperation.schedule();
}
}
} catch (CheckstylePluginException e) {
CheckstyleUIPlugin.errorDialog(getShell(), e, true);
}
return true;
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class CheckFileOnOpenPartListener method isFileAffected.
/**
* Checks if the given file is affected by the UnOpenedFilesFilter and needs to be handled on
* editor open/close.
*
* @param file
* the file to check
* @return <code>true</code> if the file is affected, <code>false</code> otherwise
*/
private boolean isFileAffected(IFile file) {
boolean affected = false;
IProject project = file.getProject();
try {
// check if checkstyle is enabled on the project
if (project.isAccessible() && project.hasNature(CheckstyleNature.NATURE_ID)) {
IProjectConfiguration config = ProjectConfigurationFactory.getConfiguration(project);
// now check if the UnOpenedFilesFilter is active
boolean unOpenedFilesFilterActive = false;
boolean filtered = false;
List<IFilter> filters = config.getFilters();
for (IFilter filter : filters) {
if (filter instanceof UnOpenedFilesFilter && ((UnOpenedFilesFilter) filter).isEnabled()) {
unOpenedFilesFilterActive = true;
}
// check if the file would be filtered out
if (filter.isEnabled() && !(filter instanceof UnOpenedFilesFilter)) {
filtered = filtered || !filter.accept(file);
}
}
affected = unOpenedFilesFilterActive && !filtered;
}
} catch (CoreException e) {
// should never happen, since editor cannot be open
// when project isn't
CheckstyleLog.log(e);
} catch (CheckstylePluginException e) {
CheckstyleLog.log(e);
}
return affected;
}
Aggregations