mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-33099 JSON Schema Mappings conflicting mappings for newly added item
- don't show conflicts for the newly added item when still editing it - always correctly update the warning - show [Project Directory] for empty folder path
This commit is contained in:
@@ -35,6 +35,7 @@ import com.jetbrains.jsonSchema.impl.JsonSchemaVersion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -239,7 +240,7 @@ public class UserDefinedJsonSchemaConfiguration {
|
||||
|
||||
@NotNull
|
||||
private static String normalizePath(String path) {
|
||||
return path.replace('\\', '/');
|
||||
return StringUtil.trimEnd(path.replace('\\', '/').replace('/', File.separatorChar), File.separatorChar);
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
@@ -267,6 +268,9 @@ public class UserDefinedJsonSchemaConfiguration {
|
||||
}
|
||||
|
||||
public String getPresentation() {
|
||||
if (mappingKind == JsonMappingKind.Directory && StringUtil.isEmpty(path)) {
|
||||
return mappingKind.getPrefix() + "[Project Directory]";
|
||||
}
|
||||
return mappingKind.getPrefix() + path;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -33,9 +33,9 @@ class JsonMappingsTableCellEditor extends AbstractTableCellEditor {
|
||||
final JPanel myWrapper;
|
||||
private final UserDefinedJsonSchemaConfiguration.Item myItem;
|
||||
private final Project myProject;
|
||||
private final Runnable myTreeUpdater;
|
||||
private final TreeUpdater myTreeUpdater;
|
||||
|
||||
public JsonMappingsTableCellEditor(UserDefinedJsonSchemaConfiguration.Item item, Project project, Runnable treeUpdater) {
|
||||
public JsonMappingsTableCellEditor(UserDefinedJsonSchemaConfiguration.Item item, Project project, TreeUpdater treeUpdater) {
|
||||
myItem = item;
|
||||
myProject = project;
|
||||
myTreeUpdater = treeUpdater;
|
||||
@@ -111,7 +111,7 @@ class JsonMappingsTableCellEditor extends AbstractTableCellEditor {
|
||||
@Override
|
||||
public boolean stopCellEditing() {
|
||||
myItem.setPath(myComponent.getChildComponent().getText());
|
||||
myTreeUpdater.run();
|
||||
myTreeUpdater.updateTree(true);
|
||||
return super.stopCellEditing();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class JsonSchemaConfigurable extends NamedConfigurable<UserDefinedJsonSch
|
||||
private final Project myProject;
|
||||
@NotNull private final String mySchemaFilePath;
|
||||
@NotNull private final UserDefinedJsonSchemaConfiguration mySchema;
|
||||
@Nullable private final Runnable myTreeUpdater;
|
||||
@Nullable private final TreeUpdater myTreeUpdater;
|
||||
@NotNull private final Function<String, String> myNameCreator;
|
||||
private JsonSchemaMappingsView myView;
|
||||
private String myDisplayName;
|
||||
@@ -40,9 +40,13 @@ public class JsonSchemaConfigurable extends NamedConfigurable<UserDefinedJsonSch
|
||||
|
||||
public JsonSchemaConfigurable(Project project,
|
||||
@NotNull String schemaFilePath, @NotNull UserDefinedJsonSchemaConfiguration schema,
|
||||
@Nullable Runnable updateTree,
|
||||
@Nullable TreeUpdater updateTree,
|
||||
@NotNull Function<String, String> nameCreator) {
|
||||
super(true, updateTree);
|
||||
super(true, () -> {
|
||||
if (updateTree != null) {
|
||||
updateTree.updateTree(true);
|
||||
}
|
||||
});
|
||||
myProject = project;
|
||||
mySchemaFilePath = schemaFilePath;
|
||||
mySchema = schema;
|
||||
@@ -88,7 +92,7 @@ public class JsonSchemaConfigurable extends NamedConfigurable<UserDefinedJsonSch
|
||||
}
|
||||
}
|
||||
});
|
||||
myView.setError(myError);
|
||||
myView.setError(myError, true);
|
||||
}
|
||||
return myView.getComponent();
|
||||
}
|
||||
@@ -206,10 +210,10 @@ public class JsonSchemaConfigurable extends NamedConfigurable<UserDefinedJsonSch
|
||||
if (myView != null) Disposer.dispose(myView);
|
||||
}
|
||||
|
||||
public void setError(String error) {
|
||||
public void setError(String error, boolean showWarning) {
|
||||
myError = error;
|
||||
if (myView != null) {
|
||||
myView.setError(error);
|
||||
myView.setError(error, showWarning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-7
@@ -50,9 +50,9 @@ public class JsonSchemaMappingsConfigurable extends MasterDetailsComponent imple
|
||||
|
||||
@NotNull
|
||||
private final Project myProject;
|
||||
private final Runnable myTreeUpdater = () -> {
|
||||
private final TreeUpdater myTreeUpdater = showWarning -> {
|
||||
TREE_UPDATER.run();
|
||||
updateWarningText();
|
||||
updateWarningText(showWarning);
|
||||
};
|
||||
|
||||
private final Function<String, String> myNameCreator = s -> createUniqueName(s);
|
||||
@@ -127,7 +127,7 @@ public class JsonSchemaMappingsConfigurable extends MasterDetailsComponent imple
|
||||
|
||||
private void addCreatedMappings(@NotNull final UserDefinedJsonSchemaConfiguration info) {
|
||||
final JsonSchemaConfigurable configurable = new JsonSchemaConfigurable(myProject, "", info, myTreeUpdater, myNameCreator);
|
||||
configurable.setError(myError);
|
||||
configurable.setError(myError, true);
|
||||
final MyNode node = new MyNode(configurable);
|
||||
addNode(node, myRoot);
|
||||
selectNodeInTree(node, true);
|
||||
@@ -144,7 +144,7 @@ public class JsonSchemaMappingsConfigurable extends MasterDetailsComponent imple
|
||||
final JsonSchemaConfigurable configurable =
|
||||
new JsonSchemaConfigurable(myProject, isHttpPath(pathToSchema) || new File(pathToSchema).isAbsolute() ? pathToSchema : new File(myProject.getBasePath(), pathToSchema).getPath(),
|
||||
info, myTreeUpdater, myNameCreator);
|
||||
configurable.setError(myError);
|
||||
configurable.setError(myError, true);
|
||||
myRoot.add(new MyNode(configurable));
|
||||
}
|
||||
((DefaultTreeModel) myTree.getModel()).reload(myRoot);
|
||||
@@ -209,7 +209,7 @@ public class JsonSchemaMappingsConfigurable extends MasterDetailsComponent imple
|
||||
return !storedList.equals(uiList);
|
||||
}
|
||||
|
||||
private void updateWarningText() {
|
||||
private void updateWarningText(boolean showWarning) {
|
||||
final MultiMap<String, UserDefinedJsonSchemaConfiguration.Item> patternsMap = new MultiMap<>();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final List<UserDefinedJsonSchemaConfiguration> list;
|
||||
@@ -221,6 +221,7 @@ public class JsonSchemaMappingsConfigurable extends MasterDetailsComponent imple
|
||||
return;
|
||||
}
|
||||
for (UserDefinedJsonSchemaConfiguration info : list) {
|
||||
info.refreshPatterns();
|
||||
final JsonSchemaPatternComparator comparator = new JsonSchemaPatternComparator(myProject);
|
||||
final List<UserDefinedJsonSchemaConfiguration.Item> patterns = info.getPatterns();
|
||||
for (UserDefinedJsonSchemaConfiguration.Item pattern : patterns) {
|
||||
@@ -247,7 +248,7 @@ public class JsonSchemaMappingsConfigurable extends MasterDetailsComponent imple
|
||||
while (children.hasMoreElements()) {
|
||||
Object o = children.nextElement();
|
||||
if (o instanceof MyNode && ((MyNode)o).getConfigurable() instanceof JsonSchemaConfigurable) {
|
||||
((JsonSchemaConfigurable) ((MyNode)o).getConfigurable()).setError(myError);
|
||||
((JsonSchemaConfigurable) ((MyNode)o).getConfigurable()).setError(myError, showWarning);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -284,7 +285,7 @@ public class JsonSchemaMappingsConfigurable extends MasterDetailsComponent imple
|
||||
@Override
|
||||
public void reset() {
|
||||
fillTree();
|
||||
updateWarningText();
|
||||
updateWarningText(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -58,7 +58,7 @@ public class JsonSchemaMappingsView implements Disposable {
|
||||
private static final String ADD_SCHEMA_MAPPING = "settings.json.schema.add.mapping";
|
||||
private static final String EDIT_SCHEMA_MAPPING = "settings.json.schema.edit.mapping";
|
||||
private static final String REMOVE_SCHEMA_MAPPING = "settings.json.schema.remove.mapping";
|
||||
private final Runnable myTreeUpdater;
|
||||
private final TreeUpdater myTreeUpdater;
|
||||
private final Consumer<String> mySchemaPathChangedCallback;
|
||||
private TableView<UserDefinedJsonSchemaConfiguration.Item> myTableView;
|
||||
private JComponent myComponent;
|
||||
@@ -71,7 +71,7 @@ public class JsonSchemaMappingsView implements Disposable {
|
||||
private boolean myInitialized;
|
||||
|
||||
public JsonSchemaMappingsView(Project project,
|
||||
Runnable treeUpdater,
|
||||
TreeUpdater treeUpdater,
|
||||
Consumer<String> schemaPathChangedCallback) {
|
||||
myTreeUpdater = treeUpdater;
|
||||
mySchemaPathChangedCallback = schemaPathChangedCallback;
|
||||
@@ -134,7 +134,7 @@ public class JsonSchemaMappingsView implements Disposable {
|
||||
JPanel panel = decorator.createPanel();
|
||||
panel.setBorder(BorderFactory.createCompoundBorder(JBUI.Borders.empty(0, 8), panel.getBorder()));
|
||||
builder.addComponentFillVertically(panel, 5);
|
||||
JLabel commentComponent = ComponentPanelBuilder.createCommentComponent("Path to file, directory or file name pattern *.config.json", false);
|
||||
JLabel commentComponent = ComponentPanelBuilder.createCommentComponent("Path to file or directory relative to project root, or file name pattern like *.config.json", false);
|
||||
commentComponent.setBorder(JBUI.Borders.empty(0, 8, 5, 0));
|
||||
builder.addComponent(commentComponent);
|
||||
|
||||
@@ -145,10 +145,10 @@ public class JsonSchemaMappingsView implements Disposable {
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
public void setError(final String text) {
|
||||
public void setError(final String text, boolean showWarning) {
|
||||
myErrorText = text;
|
||||
myError.setVisible(text != null);
|
||||
myErrorIcon.setVisible(text != null);
|
||||
myError.setVisible(showWarning && text != null);
|
||||
myErrorIcon.setVisible(showWarning && text != null);
|
||||
}
|
||||
|
||||
private void attachNavigateToSchema() {
|
||||
@@ -281,7 +281,7 @@ public class JsonSchemaMappingsView implements Disposable {
|
||||
myTableView.getListTableModel().addRow(currentItem);
|
||||
myTableView.editCellAt(myTableView.getListTableModel().getRowCount() - 1, 0);
|
||||
|
||||
myTreeUpdater.run();
|
||||
myTreeUpdater.updateTree(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ public class JsonSchemaMappingsView implements Disposable {
|
||||
++cnt;
|
||||
}
|
||||
myTableView.getListTableModel().fireTableDataChanged();
|
||||
myTreeUpdater.run();
|
||||
myTreeUpdater.updateTree(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.jsonSchema.settings.mappings;
|
||||
|
||||
public interface TreeUpdater {
|
||||
void updateTree(boolean showWarning);
|
||||
}
|
||||
Reference in New Issue
Block a user