Allow user to add MIME types without any extensions (ingest module will ignore it); prevent overwriting an existing mime or ext when adding; various minor bug fixes.

This commit is contained in:
Samuel H. Kenyon 2013-12-20 15:57:13 -05:00
parent 8f9fbabc8b
commit dc32f019dd
3 changed files with 63 additions and 37 deletions

View File

@ -36,7 +36,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jSplitPane1" min="-2" pref="460" max="-2" attributes="0"/>
<Component id="jSplitPane1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="saveButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
@ -63,7 +63,7 @@
</Component>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="dividerLocation" type="int" value="300"/>
<Property name="dividerLocation" type="int" value="430"/>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
@ -83,7 +83,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane2" pref="0" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="userTypeTextField" min="-2" pref="128" max="-2" attributes="0"/>
@ -91,11 +91,11 @@
<Component id="addTypeButton" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="removeTypeButton" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="mimeErrLabel" alignment="0" max="32767" attributes="0"/>
<Component id="mimeRemoveErrLabel" max="32767" attributes="0"/>
</Group>
<EmptySpace min="0" pref="66" max="32767" attributes="0"/>
<EmptySpace min="0" pref="196" max="32767" attributes="0"/>
</Group>
<Component id="mimeErrLabel" alignment="0" max="32767" attributes="0"/>
<Component id="mimeRemoveErrLabel" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -119,7 +119,7 @@
<Component id="removeTypeButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="mimeRemoveErrLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="77" max="32767" attributes="0"/>
<EmptySpace pref="45" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -217,11 +217,11 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="addExtButton" max="32767" attributes="0"/>
</Group>
<Component id="extErrorLabel" max="32767" attributes="0"/>
<Component id="extRemoveErrLabel" max="32767" attributes="0"/>
</Group>
<EmptySpace min="0" pref="31" max="32767" attributes="0"/>
<EmptySpace min="0" pref="66" max="32767" attributes="0"/>
</Group>
<Component id="extErrorLabel" alignment="0" max="32767" attributes="0"/>
<Component id="extRemoveErrLabel" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -233,7 +233,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="extHeaderLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane3" min="-2" pref="313" max="-2" attributes="0"/>
<Component id="jScrollPane3" min="-2" pref="285" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="userExtTextField" alignment="3" min="-2" max="-2" attributes="0"/>
@ -245,7 +245,7 @@
<Component id="removeExtButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="extRemoveErrLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="15" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>

View File

@ -160,7 +160,7 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
}
});
jSplitPane1.setDividerLocation(300);
jSplitPane1.setDividerLocation(430);
jLabel1.setText(org.openide.util.NbBundle.getMessage(FileExtMismatchConfigPanel.class, "FileExtMismatchConfigPanel.jLabel1.text")); // NOI18N
@ -202,16 +202,16 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
.addGroup(mimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(mimePanelLayout.createSequentialGroup()
.addGroup(mimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(mimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(mimePanelLayout.createSequentialGroup()
.addComponent(userTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(addTypeButton))
.addComponent(removeTypeButton)
.addComponent(mimeErrLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(mimeRemoveErrLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(0, 66, Short.MAX_VALUE)))
.addComponent(removeTypeButton))
.addGap(0, 196, Short.MAX_VALUE))
.addComponent(mimeErrLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(mimeRemoveErrLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
mimePanelLayout.setVerticalGroup(
@ -231,7 +231,7 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
.addComponent(removeTypeButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mimeRemoveErrLabel)
.addContainerGap(77, Short.MAX_VALUE))
.addContainerGap(45, Short.MAX_VALUE))
);
jSplitPane1.setLeftComponent(mimePanel);
@ -282,10 +282,10 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
.addGroup(extensionPanelLayout.createSequentialGroup()
.addComponent(userExtTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(addExtButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(extErrorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(extRemoveErrLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(0, 31, Short.MAX_VALUE)))
.addComponent(addExtButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGap(0, 66, Short.MAX_VALUE))
.addComponent(extErrorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(extRemoveErrLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
extensionPanelLayout.setVerticalGroup(
@ -294,7 +294,7 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
.addContainerGap()
.addComponent(extHeaderLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(extensionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(userExtTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
@ -305,7 +305,7 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
.addComponent(removeExtButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(extRemoveErrLabel)
.addContainerGap(15, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jSplitPane1.setRightComponent(extensionPanel);
@ -332,7 +332,7 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 460, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(saveButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
@ -356,6 +356,12 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
return;
}
if (currentExtensions.contains(newExt)) {
extErrorLabel.setForeground(Color.red);
extErrorLabel.setText("Extension already exists!");
return;
}
ArrayList<String> editedExtensions = new ArrayList<>(Arrays.asList(editableMap.get(selectedMime)));
editedExtensions.add(newExt);
@ -386,6 +392,12 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
return;
}
if (mimeList.contains(newMime)) {
mimeErrLabel.setForeground(Color.red);
mimeErrLabel.setText("MIME type already exists!");
return;
}
editableMap.put(newMime, new String[0]);
// Refresh table
@ -461,12 +473,21 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
private void updateMimeList() {
mimeList = new ArrayList<>(editableMap.keySet());
Collections.sort(mimeList);
if (mimeList.size() > 0) {
Collections.sort(mimeList);
}
}
private void updateExtList() {
currentExtensions = new ArrayList<>(Arrays.asList(editableMap.get(selectedMime)));
Collections.sort(currentExtensions);
String[] temp = editableMap.get(selectedMime);
if (temp != null) {
currentExtensions = new ArrayList<>(Arrays.asList(temp));
if (temp.length > 0) {
Collections.sort(currentExtensions);
}
} else {
currentExtensions = null;
}
}
@Override
@ -475,6 +496,7 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
// to save it back to the file after making changes.
editableMap = FileExtMismatchXML.getDefault().load();
updateMimeList();
updateExtList();
}
@Override
@ -499,8 +521,8 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
}
public void cancel() {
//FileExtMismatchXML.getDefault().reload();
clearErrLabels();
load(); // The next time this panel is opened, we want it to be fresh
}
public void ok() {
@ -512,10 +534,10 @@ public final class FileExtMismatchConfigPanel extends javax.swing.JPanel impleme
}
}
clearErrLabels();
load(); // The next time this panel is opened, we want it to be fresh
}
boolean valid() {
// TODO check whether form is consistent and complete
return true;
}

View File

@ -123,6 +123,8 @@ public class FileExtMismatchXML {
}
String[] sarray = (String[])extStrings.toArray(new String[0]);
sigTypeToExtMap.put(mimetype, sarray);
} else {
sigTypeToExtMap.put(mimetype, null); //ok to have an empty type (the ingest module will not use it)
}
}
@ -159,13 +161,15 @@ public class FileExtMismatchXML {
Element sigEl = doc.createElement(SIG_EL);
sigEl.setAttribute(SIG_MIMETYPE_ATTR, key);
ArrayList<String> extList = new ArrayList<>(Arrays.asList(sigTypeToExtMap.get(key)));
for (String ext : extList) {
Element extEl = doc.createElement(EXT_EL);
extEl.setTextContent(ext);
sigEl.appendChild(extEl);
String[] extArray = sigTypeToExtMap.get(key);
if (extArray != null) {
ArrayList<String> extList = new ArrayList<>(Arrays.asList(extArray));
for (String ext : extList) {
Element extEl = doc.createElement(EXT_EL);
extEl.setTextContent(ext);
sigEl.appendChild(extEl);
}
}
rootEl.appendChild(sigEl);
}