use of com.intellij.openapi.util.JDOMExternalizable in project intellij-community by JetBrains.
the class SystemFileProcessor method encodeFileText.
@Nullable
@Override
protected String encodeFileText(String content, VirtualFile file, Project project) throws IOException {
final String fileName = file.getName();
if (file.getParent().getName().equals(Project.DIRECTORY_STORE_FOLDER) && fileName.equals("workspace.xml")) {
List<Object> componentList = new ArrayList<>();
for (String componentName : COMPONENT_NAMES) {
Object component = project.getComponent(componentName);
if (component == null) {
try {
Class<?> aClass = Class.forName(componentName);
component = project.getComponent(aClass);
if (component == null) {
component = ServiceManager.getService(project, aClass);
}
} catch (ClassNotFoundException ignore) {
}
}
ContainerUtil.addIfNotNull(componentList, component);
}
if (!componentList.isEmpty()) {
final Element root = new Element("project");
for (final Object component : componentList) {
final Element element = new Element("component");
element.setAttribute("name", ComponentManagerImpl.getComponentName(component));
root.addContent(element);
ApplicationManager.getApplication().invokeAndWait(() -> {
if (component instanceof JDOMExternalizable) {
try {
((JDOMExternalizable) component).writeExternal(element);
} catch (WriteExternalException ignore) {
LOG.error(ignore);
}
} else if (component instanceof PersistentStateComponent) {
Object state = WriteAction.compute(() -> ((PersistentStateComponent) component).getState());
if (state == null) {
return;
}
Element element1 = state instanceof Element ? (Element) state : XmlSerializer.serialize(state);
element.addContent(element1.cloneContent());
element.setAttribute("name", StoreUtil.getStateSpec((PersistentStateComponent) component).name());
}
}, ModalityState.defaultModalityState());
}
PathMacroManager.getInstance(project).collapsePaths(root);
return JDOMUtil.writeElement(root);
}
}
return null;
}
use of com.intellij.openapi.util.JDOMExternalizable in project intellij-community by JetBrains.
the class BaseRCSettingsConfigurable method isModified.
@Override
public boolean isModified() {
try {
RunnerAndConfigurationSettings original = getSettings();
RunnerAndConfigurationSettings snapshot = getEditor().getSnapshot();
final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(original.getConfiguration().getProject());
if (runManager.findExistingConfigurationId(original) == null)
return true;
if (!super.isModified())
return false;
if (!original.isTemplate() && runManager.findExistingConfigurationId(original) == null) {
return true;
}
if (isSnapshotSpecificallyModified(runManager, original, snapshot)) {
return true;
}
if (!runManager.getBeforeRunTasks(original.getConfiguration()).equals(runManager.getBeforeRunTasks(snapshot.getConfiguration()))) {
return true;
}
if (original instanceof JDOMExternalizable && snapshot instanceof JDOMExternalizable) {
applySnapshotToComparison(original, snapshot);
Element originalElement = new Element("config");
Element snapshotElement = new Element("config");
((JDOMExternalizable) original).writeExternal(originalElement);
((JDOMExternalizable) snapshot).writeExternal(snapshotElement);
patchElementsIfNeed(originalElement, snapshotElement);
boolean result = !JDOMUtil.areElementsEqual(originalElement, snapshotElement, true);
if (!result) {
super.setModified(false);
}
return result;
}
} catch (ConfigurationException e) {
//ignore
}
return super.isModified();
}
Aggregations