use of net.sf.eclipsecs.core.config.configtypes.IConfigurationType 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.config.configtypes.IConfigurationType in project eclipse-cs by checkstyle.
the class CheckConfigurationPropertiesDialog method initialize.
/**
* Initialize the dialogs controls with the data.
*/
private void initialize() {
if (mCheckConfig == null) {
IConfigurationType[] types = mTemplate != null ? ConfigurationTypes.getConfigurableConfigTypes() : ConfigurationTypes.getCreatableConfigTypes();
mCheckConfig = mWorkingSet.newWorkingCopy(types[0]);
if (mTemplate != null) {
this.setTitle(NLS.bind(Messages.CheckConfigurationPropertiesDialog_titleCopyConfiguration, mTemplate.getName()));
this.setMessage(Messages.CheckConfigurationPropertiesDialog_msgCopyConfiguration);
String nameProposal = NLS.bind(Messages.CheckConfigurationPropertiesDialog_CopyOfAddition, mTemplate.getName());
setUniqueName(mCheckConfig, nameProposal);
mCheckConfig.setDescription(mTemplate.getDescription());
mCheckConfig.getResolvableProperties().addAll(mTemplate.getResolvableProperties());
} else {
this.setTitle(Messages.CheckConfigurationPropertiesDialog_titleCheckConfig);
this.setMessage(Messages.CheckConfigurationPropertiesDialog_msgCreateNewCheckConfig);
}
mConfigType.setInput(types);
mConfigType.setSelection(new StructuredSelection(types[0]), true);
createConfigurationEditor(mCheckConfig);
} else {
this.setTitle(Messages.CheckConfigurationPropertiesDialog_titleCheckConfig);
this.setMessage(Messages.CheckConfigurationPropertiesDialog_msgEditCheckConfig);
mConfigType.getCombo().setEnabled(false);
mConfigType.setInput(new IConfigurationType[] { mCheckConfig.getType() });
// type of existing configs cannot be changed
mConfigType.setSelection(new StructuredSelection(mCheckConfig.getType()), true);
createConfigurationEditor(mCheckConfig);
}
}
use of net.sf.eclipsecs.core.config.configtypes.IConfigurationType in project eclipse-cs by checkstyle.
the class CheckConfigurationFactory method getGlobalCheckConfigurations.
/**
* Gets the check configurations from the configuration file document.
*
* @param root
* the root element of the plugins central configuration file
* @return the global check configurations configured therein
*/
@SuppressWarnings("unchecked")
private static List<ICheckConfiguration> getGlobalCheckConfigurations(Element root) {
List<ICheckConfiguration> configs = new ArrayList<>();
List<Element> configElements = root.elements(XMLTags.CHECK_CONFIG_TAG);
for (Element configEl : configElements) {
String name = configEl.attributeValue(XMLTags.NAME_TAG);
String description = configEl.attributeValue(XMLTags.DESCRIPTION_TAG);
String location = configEl.attributeValue(XMLTags.LOCATION_TAG);
String type = configEl.attributeValue(XMLTags.TYPE_TAG);
IConfigurationType configType = ConfigurationTypes.getByInternalName(type);
// get resolvable properties
List<ResolvableProperty> props = new ArrayList<>();
List<Element> propertiesElements = configEl.elements(XMLTags.PROPERTY_TAG);
for (Element propsEl : propertiesElements) {
ResolvableProperty prop = new ResolvableProperty(propsEl.attributeValue(XMLTags.NAME_TAG), propsEl.attributeValue(XMLTags.VALUE_TAG));
props.add(prop);
}
// get additional data
Map<String, String> additionalData = new HashMap<>();
List<Element> dataElements = configEl.elements(XMLTags.ADDITIONAL_DATA_TAG);
for (Element dataEl : dataElements) {
additionalData.put(dataEl.attributeValue(XMLTags.NAME_TAG), dataEl.attributeValue(XMLTags.VALUE_TAG));
}
ICheckConfiguration checkConfig = new CheckConfiguration(name, location, description, configType, true, props, additionalData);
configs.add(checkConfig);
}
return configs;
}
use of net.sf.eclipsecs.core.config.configtypes.IConfigurationType in project eclipse-cs by checkstyle.
the class ProjectConfigurationFactory method getLocalCheckConfigs.
@SuppressWarnings("unchecked")
private static List<ICheckConfiguration> getLocalCheckConfigs(Element root, IProject project) {
List<ICheckConfiguration> configurations = new ArrayList<>();
List<Element> configElements = root.elements(XMLTags.CHECK_CONFIG_TAG);
for (Element configEl : configElements) {
final String name = configEl.attributeValue(XMLTags.NAME_TAG);
final String description = configEl.attributeValue(XMLTags.DESCRIPTION_TAG);
String location = configEl.attributeValue(XMLTags.LOCATION_TAG);
String type = configEl.attributeValue(XMLTags.TYPE_TAG);
IConfigurationType configType = ConfigurationTypes.getByInternalName(type);
if (configType instanceof ProjectConfigurationType) {
// RFE 1420212
// treat config files relative to *THIS* project
IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();
// test if the location contains the project name
if (workspaceRoot.findMember(location) == null) {
location = project.getFullPath().append(location).toString();
}
}
// get resolvable properties
List<ResolvableProperty> props = new ArrayList<>();
List<Element> propertiesElements = configEl.elements(XMLTags.PROPERTY_TAG);
for (Element propsEl : propertiesElements) {
ResolvableProperty prop = new ResolvableProperty(propsEl.attributeValue(XMLTags.NAME_TAG), propsEl.attributeValue(XMLTags.VALUE_TAG));
props.add(prop);
}
// get additional data
Map<String, String> additionalData = new HashMap<>();
List<Element> dataElements = configEl.elements(XMLTags.ADDITIONAL_DATA_TAG);
for (Element dataEl : dataElements) {
additionalData.put(dataEl.attributeValue(XMLTags.NAME_TAG), dataEl.attributeValue(XMLTags.VALUE_TAG));
}
ICheckConfiguration checkConfig = new CheckConfiguration(name, location, description, configType, false, props, additionalData);
configurations.add(checkConfig);
}
return configurations;
}
use of net.sf.eclipsecs.core.config.configtypes.IConfigurationType in project eclipse-cs by checkstyle.
the class CheckConfigurationFactory method loadBuiltinConfigurations.
/**
* Loads the built-in check configurations defined in plugin.xml or custom fragments.
*/
private static void loadBuiltinConfigurations() {
IExtensionRegistry pluginRegistry = Platform.getExtensionRegistry();
IConfigurationElement[] elements = pluginRegistry.getConfigurationElementsFor(CONFIGS_EXTENSION_POINT);
int currentMaxDefaultWeight = -1;
ICheckConfiguration defaultBuiltInCheckConfig = null;
for (int i = 0; i < elements.length; i++) {
String name = elements[i].getAttribute(XMLTags.NAME_TAG);
String description = elements[i].getAttribute(XMLTags.DESCRIPTION_TAG);
String location = elements[i].getAttribute(XMLTags.LOCATION_TAG);
String defaultWeightAsString = elements[i].getAttribute(XMLTags.DEFAULT_WEIGHT);
final int defaultWeight = defaultWeightAsString != null ? Integer.parseInt(defaultWeightAsString) : 0;
IConfigurationType configType = ConfigurationTypes.getByInternalName("builtin");
Map<String, String> additionalData = new HashMap<>();
additionalData.put(BuiltInConfigurationType.CONTRIBUTOR_KEY, elements[i].getContributor().getName());
List<ResolvableProperty> props = new ArrayList<>();
IConfigurationElement[] propEls = elements[i].getChildren(XMLTags.PROPERTY_TAG);
for (IConfigurationElement propEl : propEls) {
props.add(new ResolvableProperty(propEl.getAttribute(XMLTags.NAME_TAG), propEl.getAttribute(XMLTags.VALUE_TAG)));
}
ICheckConfiguration checkConfig = new CheckConfiguration(name, location, description, configType, true, props, additionalData);
sConfigurations.add(checkConfig);
if (defaultWeight > currentMaxDefaultWeight) {
currentMaxDefaultWeight = defaultWeight;
defaultBuiltInCheckConfig = checkConfig;
}
}
sDefaultBuiltInConfig = defaultBuiltInCheckConfig;
}
Aggregations