Skip to content

Commit

Permalink
#28 autocomplete of common HTTP header
Browse files Browse the repository at this point in the history
  • Loading branch information
subwiz committed Jan 5, 2015
1 parent eee0267 commit be2ab87
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.wiztools.restclient.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
*
* @author subhash
*/
public class ContentTypesCommon {
private static final List<String> contentTypes = new ArrayList<>();

static {
contentTypes.add("Accept");
contentTypes.add("Accept-Charset");
contentTypes.add("Accept-Encoding");
contentTypes.add("Accept-Language");
contentTypes.add("Content-MD5");
contentTypes.add("Content-Type");
contentTypes.add("Date");
contentTypes.add("Expect");
contentTypes.add("From");
contentTypes.add("If-Match");
contentTypes.add("If-Modified-Since");
contentTypes.add("If-None-Match");
contentTypes.add("If-Range");
contentTypes.add("If-Unmodified-Since");
contentTypes.add("Max-Forwards");
contentTypes.add("Origin");
contentTypes.add("Pragma");
contentTypes.add("Range");
contentTypes.add("Referer");
contentTypes.add("TE");
contentTypes.add("User-Agent");
contentTypes.add("Upgrade");
contentTypes.add("Via");
contentTypes.add("Warning");
}

public static List<String> getCommon() {
return Collections.unmodifiableList(contentTypes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.wiztools.restclient.ui.resheader.ResHeaderPanel;
import org.wiztools.restclient.ui.resstatus.ResStatusPanel;
import org.wiztools.restclient.ui.restest.ResTestPanel;
import org.wiztools.restclient.util.ContentTypesCommon;
import org.wiztools.restclient.util.HttpUtil;
import org.wiztools.restclient.util.Util;

Expand Down Expand Up @@ -94,7 +95,8 @@ private JTabbedPane initJTPRequest(){
jtp.addTab("Method", jp_req_method.getComponent());

// Headers Tab
jp_2col_req_headers = new TwoColumnTablePanel(new String[]{"Header", "Value"}, rest_ui);
jp_2col_req_headers = new TwoColumnTablePanel(
new String[]{"Header", "Value"}, ContentTypesCommon.getCommon(), rest_ui);
jtp.addTab("Header", jp_2col_req_headers);

// Cookies Tab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.swing.*;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import org.wiztools.commons.CollectionsUtil;
import org.wiztools.commons.MultiValueMap;
import org.wiztools.commons.MultiValueMapLinkedHashSet;
Expand All @@ -37,13 +39,6 @@ private void initMultiEntryDialog(){
MultiEntryAdd callback = new MultiEntryAdd() {
@Override
public void add(Map<String, String> keyValuePair, List<String> invalidLines) {
Object[][] data = model.getData();
List<String> keys = new ArrayList<String>();
for(Object[] o: data){
String key = (String)o[0];
keys.add(key);
}

int successCount = 0;
for(String key: keyValuePair.keySet()){
String value = keyValuePair.get(key);
Expand Down Expand Up @@ -76,7 +71,7 @@ public MultiValueMap<String, String> getData() {
return CollectionsUtil.EMPTY_MULTI_VALUE_MAP;
}

MultiValueMap<String, String> out = new MultiValueMapLinkedHashSet<String, String>();
MultiValueMap<String, String> out = new MultiValueMapLinkedHashSet<>();
for (Object[] d1 : d) {
String key = (String) d1[0];
String value = (String) d1[1];
Expand All @@ -89,8 +84,12 @@ public MultiValueMap<String, String> getData() {
public void setData(MultiValueMap<String, String> data) {
model.setData(data);
}

public TwoColumnTablePanel(final String[] title, final RESTUserInterface ui) {
this(title, Collections.EMPTY_LIST, ui);
}

public TwoColumnTablePanel(final String[] title, List<String> keys, final RESTUserInterface ui) {

this.rest_ui = ui;

Expand Down Expand Up @@ -171,6 +170,7 @@ private void showPopup(MouseEvent e) {
JLabel jl_value = new JLabel("Value: ");
final int TEXT_FIELD_SIZE = 12;
final JTextField jtf_key = new JTextField(TEXT_FIELD_SIZE);
if(!keys.isEmpty()) {AutoCompleteDecorator.decorate(jtf_key, keys, false);}
final JTextField jtf_value = new JTextField(TEXT_FIELD_SIZE);
jl_key.setDisplayedMnemonic('k');
jl_key.setLabelFor(jtf_key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ static void select(ContentTypeCharsetComponent jp_content_type_charset,
}
}
}
catch(IOException ex) {
// Do nothing!
}
catch(XMLException ex){
catch(IOException | XMLException ex) {
// Do nothing!
}
}
Expand Down

0 comments on commit be2ab87

Please sign in to comment.