use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.
the class InspectionProfileSchemesPanel method createSchemeActions.
@Override
protected AbstractSchemeActions<InspectionProfileModifiableModel> createSchemeActions() {
return new DescriptionAwareSchemeActions<InspectionProfileModifiableModel>(this) {
@Nullable
@Override
public String getDescription(@NotNull InspectionProfileModifiableModel scheme) {
SingleInspectionProfilePanel inspectionProfile = ((InspectionProfileSchemesModel) getModel()).getProfilePanel(scheme);
return inspectionProfile.getProfile().getDescription();
}
@Override
protected void setDescription(@NotNull InspectionProfileModifiableModel scheme, @NotNull String newDescription) {
InspectionProfileModifiableModel inspectionProfile = InspectionProfileSchemesPanel.this.getModel().getProfilePanel(scheme).getProfile();
if (!Comparing.strEqual(newDescription, inspectionProfile.getDescription())) {
inspectionProfile.setDescription(newDescription);
inspectionProfile.setModified(true);
}
}
@Override
protected void importScheme(@NotNull String importerName) {
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) {
@Override
public boolean isFileSelectable(VirtualFile file) {
return file.getFileType().equals(StdFileTypes.XML);
}
};
descriptor.setDescription("Choose profile file");
FileChooser.chooseFile(descriptor, myProject, null, file -> {
if (file != null) {
final InspectionProfileImpl profile;
try {
profile = InspectionToolsConfigurable.importInspectionProfile(JDOMUtil.load(file.getInputStream()), myAppProfileManager, myProject);
final SingleInspectionProfilePanel existed = InspectionProfileSchemesPanel.this.getModel().getProfilePanel(profile);
if (existed != null) {
if (Messages.showOkCancelDialog(myProject, "Profile with name \'" + profile.getName() + "\' already exists. Do you want to overwrite it?", "Warning", Messages.getInformationIcon()) != Messages.OK) {
return;
}
getModel().removeScheme(existed.getProfile());
}
InspectionProfileModifiableModel model = new InspectionProfileModifiableModel(profile);
model.setModified(true);
addProfile(model);
selectScheme(model);
} catch (JDOMException | InvalidDataException | IOException e) {
LOG.error(e);
}
}
});
}
@Override
protected void resetScheme(@NotNull InspectionProfileModifiableModel scheme) {
final SingleInspectionProfilePanel panel = InspectionProfileSchemesPanel.this.getModel().getProfilePanel(scheme);
panel.performProfileReset();
}
@Override
protected void duplicateScheme(@NotNull InspectionProfileModifiableModel scheme, @NotNull String newName) {
final InspectionProfileModifiableModel newProfile = copyToNewProfile(scheme, myProject, newName, false);
addProfile(newProfile);
myConfigurable.selectProfile(newProfile);
selectScheme(newProfile);
}
@Override
protected void exportScheme(@NotNull InspectionProfileModifiableModel scheme, @NotNull String exporterName) {
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
descriptor.setDescription("Choose directory to store profile file");
FileChooser.chooseFile(descriptor, myProject, null, dir -> {
try {
LOG.assertTrue(true);
Element element = scheme.writeScheme(false);
Path file = Paths.get(dir.getPath(), sanitizeFileName(scheme.getName()) + ".xml");
if (Files.isRegularFile(file.toAbsolutePath()) && Messages.showOkCancelDialog(myProject, "File \'" + file + "\' already exist. Do you want to overwrite it?", "Warning", Messages.getQuestionIcon()) != Messages.OK) {
return;
}
JdomKt.write(element, file);
} catch (IOException e1) {
LOG.error(e1);
}
});
}
@Override
protected void onSchemeChanged(@Nullable InspectionProfileModifiableModel scheme) {
super.onSchemeChanged(scheme);
if (scheme != null) {
myConfigurable.selectProfile(scheme);
}
}
@Override
protected void renameScheme(@NotNull InspectionProfileModifiableModel scheme, @NotNull String newName) {
scheme.setName(newName);
}
@Override
protected void copyToProject(@NotNull InspectionProfileModifiableModel scheme) {
copyToAnotherLevel(scheme, true);
}
@Override
protected void copyToIDE(@NotNull InspectionProfileModifiableModel scheme) {
copyToAnotherLevel(scheme, false);
}
@Override
protected Class<InspectionProfileModifiableModel> getSchemeType() {
return InspectionProfileModifiableModel.class;
}
private void copyToAnotherLevel(InspectionProfileModifiableModel profile, boolean copyToProject) {
String name = SchemeNameGenerator.getUniqueName(profile.getName(), schemeName -> ((InspectionProfileSchemesModel) getModel()).hasName(schemeName, copyToProject));
final InspectionProfileModifiableModel newProfile = copyToNewProfile(profile, myProject, name, true);
addProfile(newProfile);
selectScheme(newProfile);
getSchemesPanel().startEdit();
}
};
}
use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.
the class ModuleBasedConfiguration method clone.
@Override
public ModuleBasedConfiguration clone() {
final Element element = new Element(TO_CLONE_ELEMENT_NAME);
try {
writeExternal(element);
RunConfiguration configuration = getFactory().createTemplateConfiguration(getProject());
configuration.setName(getName());
configuration.readExternal(element);
return (ModuleBasedConfiguration) configuration;
} catch (InvalidDataException | WriteExternalException e) {
LOG.error(e);
return null;
}
}
use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.
the class LogConsolePreferences method loadState.
@Override
public void loadState(final Element object) {
try {
final List children = object.getChildren(FILTER);
for (Object child : children) {
Element filterElement = (Element) child;
final LogFilter filter = new LogFilter();
filter.readExternal(filterElement);
setFilterSelected(filter, Boolean.parseBoolean(filterElement.getAttributeValue(IS_ACTIVE)));
}
DefaultJDOMExternalizer.readExternal(this, object);
} catch (InvalidDataException e) {
LOG.error(e);
}
}
use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.
the class RunInspectionAction method copyToolWithSettings.
private static InspectionToolWrapper copyToolWithSettings(@NotNull final InspectionToolWrapper tool) {
final Element options = new Element("copy");
tool.getTool().writeSettings(options);
final InspectionToolWrapper copiedTool = tool.createCopy();
try {
copiedTool.getTool().readSettings(options);
} catch (InvalidDataException e) {
throw new RuntimeException(e);
}
return copiedTool;
}
use of com.intellij.openapi.util.InvalidDataException in project intellij-community by JetBrains.
the class CodeStyleSchemeImpl method init.
private void init(@Nullable CodeStyleScheme parentScheme, @Nullable Element root) {
if (parentScheme == null) {
myCodeStyleSettings = new CodeStyleSettings();
} else {
CodeStyleSettings parentSettings = parentScheme.getCodeStyleSettings();
myCodeStyleSettings = parentSettings.clone();
while (parentSettings.getParentSettings() != null) {
parentSettings = parentSettings.getParentSettings();
}
myCodeStyleSettings.setParentSettings(parentSettings);
}
if (root != null) {
try {
myCodeStyleSettings.readExternal(root);
} catch (InvalidDataException e) {
LOG.error(e);
}
}
}
Aggregations