use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class CheckConfigurationPropertiesDialog method createDialogArea.
/**
* Creates the dialogs main contents.
*
* @param parent
* the parent composite
*/
@Override
protected Control createDialogArea(Composite parent) {
// set the logo
this.setTitleImage(CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.PLUGIN_LOGO));
Composite composite = (Composite) super.createDialogArea(parent);
Composite contents = new Composite(composite, SWT.NULL);
contents.setLayout(new GridLayout(2, false));
GridData fd = new GridData(GridData.FILL_BOTH);
contents.setLayoutData(fd);
Label lblConfigType = new Label(contents, SWT.NULL);
lblConfigType.setText(Messages.CheckConfigurationPropertiesDialog_lblConfigType);
fd = new GridData();
// this is a weird hack to find the longest label
// this is done to have a nice ordered appearance of the this label
// and the labels below
// this is very difficult to do, because they belong to different
// layouts
GC gc = new GC(lblConfigType);
int nameSize = gc.textExtent(Messages.CheckConfigurationPropertiesDialog_lblName).x;
int locationsSize = gc.textExtent(Messages.CheckConfigurationPropertiesDialog_lblLocation).x;
int max = Math.max(nameSize, locationsSize);
gc.dispose();
fd.widthHint = max;
lblConfigType.setLayoutData(fd);
mConfigType = new ComboViewer(contents);
fd = new GridData();
mConfigType.getCombo().setLayoutData(fd);
mConfigType.setContentProvider(new ArrayContentProvider());
mConfigType.setLabelProvider(new LabelProvider() {
/**
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
return ((IConfigurationType) element).getName();
}
/**
* @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
*/
@Override
public Image getImage(Object element) {
return ConfigurationTypesUI.getConfigurationTypeImage((IConfigurationType) element);
}
});
mConfigType.addSelectionChangedListener(new ISelectionChangedListener() {
/**
* @see ISelectionChangedListener#selectionChanged(
* org.eclipse.jface.viewers.SelectionChangedEvent)
*/
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof IStructuredSelection) {
IConfigurationType type = (IConfigurationType) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (mConfigType.getCombo().isEnabled()) {
String oldName = mCheckConfig.getName();
String oldDescr = mCheckConfig.getDescription();
mCheckConfig = mWorkingSet.newWorkingCopy(type);
try {
mCheckConfig.setName(oldName);
} catch (CheckstylePluginException e) {
// NOOP
}
mCheckConfig.setDescription(oldDescr);
}
createConfigurationEditor(mCheckConfig);
}
}
});
mEditorPlaceHolder = new Composite(contents, SWT.NULL);
GridLayout layout = new GridLayout(1, true);
layout.marginWidth = 0;
layout.marginHeight = 0;
mEditorPlaceHolder.setLayout(layout);
fd = new GridData(GridData.FILL_HORIZONTAL);
fd.horizontalSpan = 2;
mEditorPlaceHolder.setLayoutData(fd);
return composite;
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class CheckConfigurationPropertiesDialog method okPressed.
/**
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
@Override
protected void okPressed() {
try {
// Check if the configuration is valid
mCheckConfig = mConfigurationEditor.getEditedWorkingCopy();
CheckConfigurationTester tester = new CheckConfigurationTester(mCheckConfig);
List<ResolvableProperty> unresolvedProps = tester.getUnresolvedProperties();
if (!unresolvedProps.isEmpty()) {
MessageDialog dialog = new MessageDialog(getShell(), Messages.CheckConfigurationPropertiesDialog_titleUnresolvedProps, null, NLS.bind(Messages.CheckConfigurationPropertiesDialog_msgUnresolvedProps, // $NON-NLS-1$
"" + unresolvedProps.size()), MessageDialog.WARNING, new String[] { Messages.CheckConfigurationPropertiesDialog_btnEditProps, Messages.CheckConfigurationPropertiesDialog_btnContinue, Messages.CheckConfigurationPropertiesDialog_btnCancel }, 0);
int result = dialog.open();
if (0 == result) {
ResolvablePropertiesDialog propsDialog = new ResolvablePropertiesDialog(getShell(), mCheckConfig);
propsDialog.open();
return;
} else if (1 == result) {
super.okPressed();
} else if (2 == result) {
return;
}
} else {
super.okPressed();
}
} catch (CheckstylePluginException e) {
CheckstyleLog.log(e);
this.setErrorMessage(e.getLocalizedMessage());
}
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class CheckConfigurationWorkingSetEditor method copyCheckConfig.
/**
* Copy an existing config.
*/
private void copyCheckConfig() {
IStructuredSelection selection = (IStructuredSelection) mViewer.getSelection();
ICheckConfiguration sourceConfig = (ICheckConfiguration) selection.getFirstElement();
if (sourceConfig == null) {
//
return;
}
try {
// Open the properties dialog to change default name and description
CheckConfigurationPropertiesDialog dialog = new CheckConfigurationPropertiesDialog(getShell(), null, mWorkingSet);
dialog.setTemplateConfiguration(sourceConfig);
dialog.setBlockOnOpen(true);
if (Window.OK == dialog.open()) {
CheckConfigurationWorkingCopy newConfig = dialog.getCheckConfiguration();
// Copy the source configuration into the new internal config
CheckConfigurationFactory.copyConfiguration(sourceConfig, newConfig);
mWorkingSet.addCheckConfiguration(newConfig);
mViewer.setInput(mWorkingSet.getWorkingCopies());
mViewer.refresh();
}
} catch (CheckstylePluginException e) {
CheckstyleUIPlugin.errorDialog(getShell(), e, true);
}
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class CheckConfigurationWorkingSetEditor method configureCheckConfig.
private void configureCheckConfig() {
CheckConfigurationWorkingCopy config = (CheckConfigurationWorkingCopy) ((IStructuredSelection) mViewer.getSelection()).getFirstElement();
if (config != null) {
try {
// test if file exists
config.getCheckstyleConfiguration();
CheckConfigurationConfigureDialog dialog = new CheckConfigurationConfigureDialog(getShell(), config);
dialog.setBlockOnOpen(true);
dialog.open();
} catch (CheckstylePluginException e) {
CheckstyleUIPlugin.warningDialog(getShell(), NLS.bind(Messages.errorCannotResolveCheckLocation, config.getLocation(), config.getName()), e);
}
}
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class ProjectConfigurationEditor method getEditedWorkingCopy.
/**
* {@inheritDoc}
*/
@Override
public CheckConfigurationWorkingCopy getEditedWorkingCopy() throws CheckstylePluginException {
mWorkingCopy.setName(mConfigName.getText());
mWorkingCopy.setDescription(mDescription.getText());
mWorkingCopy.getAdditionalData().put(ExternalFileConfigurationType.KEY_PROTECT_CONFIG, // $NON-NLS-1$
"" + mChkProtectConfig.getSelection());
try {
mWorkingCopy.setLocation(mLocation.getText());
} catch (CheckstylePluginException e) {
String location = mLocation.getText();
if (Strings.emptyToNull(location) == null) {
throw e;
}
ICheckConfigurationWorkingSet ws = mCheckConfigDialog.getCheckConfigurationWorkingSet();
IPath tmp = new Path(location);
boolean isFirstPartProject = ResourcesPlugin.getWorkspace().getRoot().getProject(tmp.segment(0)).exists();
if (ws instanceof LocalCheckConfigurationWorkingSet && !isFirstPartProject) {
location = ((LocalCheckConfigurationWorkingSet) ws).getProject().getFullPath().append(location).toString();
mLocation.setText(location);
} else if (ws instanceof GlobalCheckConfigurationWorkingSet && !isFirstPartProject) {
throw new CheckstylePluginException(NLS.bind(Messages.ProjectConfigurationEditor_msgNoProjectInWorkspace, tmp.segment(0)));
}
if (ensureFileExists(location)) {
mWorkingCopy.setLocation(mLocation.getText());
} else {
throw e;
}
}
return mWorkingCopy;
}
Aggregations