java - Binding form elements to persistent storage in IntelliJ plugin -


i have started trying make own intellij plugin , can't figure out how save persistent information on bound form components.

i followed right click on form, data binding wizard, , matched listed. modified generated methods handle objects (or in case, 1 object) not bound (a jspinner).

how supposed persistent storage automatically save/update when state of component on form changed?

here persistentstatecomponent class:

import com.intellij.openapi.components.persistentstatecomponent; import com.intellij.openapi.components.state; import com.intellij.openapi.components.storage; import com.intellij.openapi.components.storagepathmacros; import com.intellij.util.xmlb.xmlserializerutil;  @state(         name = "hastebin configuration",         reloadable = true,         storages = {                 @storage(id = "other", file = storagepathmacros.app_config + "/hastebin.xml")         } ) public class hastebinservice implements persistentstatecomponent<hastebinservice> {      private string host = "hastebin.com";     private string msgsuccess = "share hastebin successful.<br>link waiting in clipboard.";     private string msgfailure = "something went wrong.<br><br>problem description: {error}<br><br>please try again , problem persists, contact author.";     private boolean logpastes = false;     private int port = 80;     private boolean usefileassoc = true;     private boolean usessl = false;      public string gethost() {         return this.host;     }      public boolean getlogpastes() {         return this.logpastes;     }      public string getmsgfailure() {         return this.msgfailure;     }      public string getmsgsuccess() {         return this.msgsuccess;     }      public int getport() {         return this.port;     }      @override     public hastebinservice getstate() {         return this;     }      public boolean getusefileassoc() {         return this.usefileassoc;     }      public boolean getusessl() {         return this.usessl;     }      @override     public void loadstate(hastebinservice state) {         xmlserializerutil.copybean(state, this);     }      public void sethost(string host) {         this.host = host;         system.out.println("testing");     }      public void setlogpastes(boolean logpastes) {         this.logpastes = logpastes;     }      public void setmsgfailure(string msgfailure) {         this.msgfailure = msgfailure;     }      public void setmsgsuccess(string msgsuccess) {         this.msgsuccess = msgsuccess;     }      public void setport(int port) {         this.port = port;     }      public void setusefileassoc(boolean usefileassoc) {         this.usefileassoc = usefileassoc;     }      public void setusessl(boolean usessl) {         this.usessl = usessl;     }  } 

here form class:

import com.intellij.ui.components.jbscrollpane;  import javax.swing.jcheckbox; import javax.swing.jcomponent; import javax.swing.jformattedtextfield; import javax.swing.jlabel; import javax.swing.jpanel; import javax.swing.jscrollpane; import javax.swing.jspinner; import javax.swing.jtabbedpane; import javax.swing.jtable; import javax.swing.jtextfield; import javax.swing.jviewport; import javax.swing.spinnernumbermodel; import java.awt.color; import java.awt.event.actionlistener;  public class settingspanel {     private jtabbedpane hastetabconfig;     private jcheckbox chkusessl;     private jcheckbox chkfileassoc;     private jcheckbox chkloghistory;     private jtextfield txtsuccess;     private jtextfield txtfailure;     private jtextfield txtdomain;     private jlabel lblprotocol;     private jspinner spinport;     private jpanel rootpanel;     private jscrollpane scrollpane;     private jpanel scrollpanel;     private jtable tblhistory;      public settingspanel() {         this.scrollpanel.setopaque(false);          this.chkusessl.addactionlistener(new actionlistener() {             @override             public void actionperformed(java.awt.event.actionevent e) {                 updateprotocol();             }         });     }      private void createuicomponents() {         // scroll pane         this.scrollpane = new jbscrollpane();         this.scrollpane.setbackground(new color(230, 230, 230));         this.scrollpane.setviewport(new customviewport(this.scrollpanel));         this.scrollpane.setopaque(false);         this.scrollpane.getverticalscrollbar().setblockincrement(20);         this.scrollpane.getverticalscrollbar().setunitincrement(16);          // port number         this.spinport = new jspinner(new spinnernumbermodel(80, 1, 65535, 1));         jformattedtextfield textfield = ((jspinner.defaulteditor)this.spinport.geteditor()).gettextfield();         textfield.setcolumns(1);     }      public void getdata(hastebinservice data) {         this.getunbounddata(data);         data.sethost(this.txtdomain.gettext());         data.setusessl(this.chkusessl.isselected());         data.setusefileassoc(this.chkfileassoc.isselected());         data.setlogpastes(this.chkloghistory.isselected());         data.setmsgsuccess(this.txtsuccess.gettext());         data.setmsgfailure(this.txtfailure.gettext());     }      private void getunbounddata(hastebinservice data) {         data.setport((int)this.spinport.getvalue());     }      public jpanel getrootpanel() {         return this.rootpanel;     }      public boolean ismodified(hastebinservice data) {         if (this.isunboundmodified(data)) return true;         if (this.txtdomain.gettext() != null ? !this.txtdomain.gettext().equals(data.gethost()) : data.gethost() != null)             return true;         if (this.chkusessl.isselected() != data.getusessl()) return true;         if (this.chkfileassoc.isselected() != data.getusefileassoc()) return true;         if (this.chkloghistory.isselected() != data.getlogpastes()) return true;         if (this.txtsuccess.gettext() != null ? !this.txtsuccess.gettext().equals(data.getmsgsuccess()) : data.getmsgsuccess() != null)             return true;         if (this.txtfailure.gettext() != null ? !this.txtfailure.gettext().equals(data.getmsgfailure()) : data.getmsgfailure() != null)             return true;         return false;     }      private boolean isunboundmodified(hastebinservice data) {         if ((int)this.spinport.getvalue() != data.getport()) return true;         return false;     }      public void setdata(hastebinservice data) {         this.setunbounddata(data);         this.txtdomain.settext(data.gethost());         this.chkusessl.setselected(data.getusessl());         this.chkfileassoc.setselected(data.getusefileassoc());         this.chkloghistory.setselected(data.getlogpastes());         this.txtsuccess.settext(data.getmsgsuccess());         this.txtfailure.settext(data.getmsgfailure());         this.updateprotocol();     }      public void setunbounddata(hastebinservice data) {         this.spinport.setvalue(data.getport());     }      private void updateprotocol() {         this.lblprotocol.settext("http" + (this.chkusessl.isselected() ? "s" : "") + "://");     }      private class customviewport extends jviewport {          public customviewport(jcomponent component) {             this.setview(component);             this.setopaque(false);         }     } } 

the intellij idea codebase not contain standard databinding solution automatically updating persistent component when form changes. jetbrains' own code copies fields form component manually.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -