Dynamically changing/updating a JTable

I have a blank JTable that will add rows as the user clicks the "add rows". My dilemma is some of the objects in the rows are comprised of JCheckBoxes. I need to know how to create an actual checkbox in those spots, without creating a sublass the extends DefaultTableModel. Also i can get everything to display on the table when the button is pushed but i just cant render the components.
I do know how to add the check boxes in the rows if the JTable is setup and never chaned from the beginning but I dont understand how to over come this problem for a dynamic table.
Thanks in advance
Chris
Some code snippets.
private static DefaultTableModel model = new DefaultTableModel();
private JTable jTable = new JTable(model);
//below is what is called when the "add row" button has just been pushed
public static void setPricingTab()
    model.addRow(getRowInfo());
  }//end public static void setPricingTab()
  public static Object[] getRowInfo()
    list[0]=ConsecCheckBox.getBoxName(); //get most recent selected edition
    list[1]=new Boolean(false);
    list[2]="Monday";
    list[3]="Tuesday";
    list[4]="Wednesday";
    list[5]="Thursday";
    list[6]="Friday";
    list[7]="Saturday";
    list[8]=new JTextArea("Price",10,10);
    list[8]=new Boolean(false);
    list[10]=null;
    return list;
//im sure i should be rendering here or in the setPricingTab()
//but this is where i am stuck
  }

Since you only post snippets of code its hard to tell whats wrong. Here is a simple example that I think does what you want:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class TableBoolean extends JFrame
    private final static String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    JTable table;
    DefaultTableModel model;
    public TableBoolean()
        //  Create table
        Object[][] data = { {"A", new Boolean(false)}, {"B", new Boolean(true)} };
        String[] columnNames = {"String","Boolean"};
        model = new DefaultTableModel(data, columnNames);
        table = new JTable(model)
            //  Returning the Class of each column will allow different
            //  renderers to be used based on Class
            public Class getColumnClass(int column)
                return getValueAt(0, column).getClass();
            public boolean isCellEditable(int row, int column)
                return true;
        //  Add table and a Button panel to the frame
        JScrollPane scrollPane = new JScrollPane( table );
        getContentPane().add( scrollPane );
        JButton button = new JButton( "Add Row" );
        button.addActionListener( new ActionListener()
            public void actionPerformed(ActionEvent e)
                Object[] newRow = new Object[2];
                int row = table.getRowCount() + 1;
                newRow[0] = LETTERS.substring(row-1, row);
                newRow[1] = (row % 2 == 0) ? new Boolean(true) : new Boolean(false);
                model.addRow( newRow );
        getContentPane().add( button, BorderLayout.SOUTH );
    public static void main(String[] args)
        TableBoolean frame = new TableBoolean();
        frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
        frame.pack();
        frame.setVisible(true);
}

Similar Messages

  • Dynamically changing rows in JTable don't re-render themselves

    Hi all,
    I've created a customized JTable and component editors/renderers. I also created a class that dynamically inserts new rows into the JTable and can also move entire rows up and down in the JTable. Dynamic insertion is working fine, but I'm having a problem with dynamically moving the rows up and down. One of my implementations has a table with three columns, the first column is always a JLabel in a JPanel, the second column is a variety of custom editors, and the third column is a custom editor for a custom JButton. If I change the value of either column 2 or 3 and then try to change the rows position in the table (up/down), then the cell that was edited remains blank until I click anywhere in the row that has the blank cell. But if I edit either column 2 or 3 and then click on the cell for column 1 in the same row and dynamically change its position (up/down) then the cells are rendered correctly.
    I've tried numerous ways to fix this problem, including fireTableDataChanged() and repaint() on the component in the cell. Any help would be greatly appreciated,
    amlandis

    So I tried updating the UI, but that didn't fix it.
    Do you explictly call editor.stopCellEditing() ? That sets the new value to your model. I override all stop editing methods and make them call their cancelEditing counterparts... and during debugging I watch the model and it has the correct data. I think my table sometime gets stuck in an isEditing() == true state. But is there no way to say setEditing(false)?
    From the BasicTableUI below... it seems like if my table gets into its editing state, the cells won't be rendered.
        private void paintCell(Graphics g, Rectangle cellRect, int row, int column) {
            if (table.isEditing() && table.getEditingRow()==row &&
                                     table.getEditingColumn()==column) {
                Component component = table.getEditorComponent();
             component.setBounds(cellRect);
                component.validate();
            else {
                TableCellRenderer renderer = table.getCellRenderer(row, column);
                Component component = table.prepareRenderer(renderer, row, column);
                rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y,
                                            cellRect.width, cellRect.height, true);
        }

  • Dynamically Updating a JTable

    I am developing an EPOS system using java, that uses a JTable to display the recipt, before it is printed.
    I have a class for the recipt data, stored in a vector which works and using observers fires events to the gui when things are added etc. My problem comes when i try to dynamically change the tables content, my idea was to create a new table, fill it with the new data, set the scroll pane around the new table and call revalidate to show the new table.
    This is possible but seems far too much work to just update a table! I would also assume the amount of extra garbage collection would require extra processing that seems pointless.
    Is there another way i could do it? Ideally i just want to refresh the content in the table for each update sent by the observable.
    Thanks

    Make your TableModel observe your observable and update it's contents. Remember to fire the appropriate event after the update.

  • Dynamic update of JTable.

    Hi to all,
    I have created JTable where it is retrieving data from database but i want it to be dynamically change as the records are added or deleted to the database reflection in the JTable has to be done.
    Thanks in advance.
    khiz_eng

    You can create thread which runs every few seconds
    and in ModelTable class , you can call fireTableStructure method.
    -shbh

  • Dynamically Changing Labels for Multi Row Block Buttons

    Forms [32 Bit] Version 9.0.4.1.0 (Production)
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
    On my local: Windows 7 OS
    I am having a difficult time in doing the following in forms, and not sure if it can be done?
    I have a multi row block,based on DB table, which displays filename and another column from the table.
    It also has a push button on each row, which opens and displays the physical file from its source, when clicked. The filename thus can have 3 diff statuses depending on its sources and accordingly corresponding button should display appropriate label:
    a) View Image (its is in content server and successfully imaged. In this case I display the file in the browser, from the content server, when the button is clicked)
    b) View File (Display the file from file system)
    c) View Error (Display imaging error message from the table, as file failed to make it to the imaging server)
    I have this logic currently coded in the post query trigger, at the block level, and tried using set_item_property(button_id, label, <button_lable>), where I programmatically set the button lable, based on the file status (imaged, not imaged or has error) in that row. This wroks well, only if all the files in the multi row block have the same status. If each of them have diff statuses, then only last processed files's status gets reflected into the button label. For eg: The file in the first row of the block is imaged, and one in the second row has an imaging error. The button label for the first row should say 'View Image' and button for the second row should say 'View Error'. But now buttons for both the rows display 'View Error', as thats what got processed last!
    I __can not use set_item_instance property for 'label'__ (which lets us dynamically change the label on the push buttons).
    Is there any way to do this for ORacle forms? I am now playing with having 3 diff button items in that block, laying them on top of each other and showing only those that are appropriate and hiding the others... But I am not sure it is going to give me what I need? I think I am going to end up facing the same issues as in above case!!
    Any expert advice is highly appreciated.
    Thanks in advance for your time:
    Libran_Girl
    Edited by: libran on Aug 30, 2011 8:04 AM
    Edited by: libran on Aug 30, 2011 8:05 AM

    <p>I have just updated this existing PJC, that was originally constructed to handle Text Fields. You can, now, also handle buttons with it.
    Set the Button's Implementation Class property to : oracle.forms.fd.MultiButton.
    </p>
    This is the code you have to put one triggers of your based block:
    When-New-Record-Instance trigger: (based on the EMP table)
    declare
         LN$Pos  pls_integer ;
         LN$Rec  pls_integer := Get_Block_Property('EMP', CURRENT_RECORD) ;
         LN$Max  pls_integer := Get_Block_Property('EMP', RECORDS_DISPLAYED) ;
         LC$C    Varchar2(15) ;
    Begin     
         LN$Pos :=  LN$Rec - (trunc(LN$Rec/LN$Max) * LN$Max) ;
         If LN$Pos = 0 Then LN$Pos := LN$Max ; End if ;
         If LN$Pos > 0 Then
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_LOG', 'true' );
              -- Add the new item --
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_NEW_REC', to_char(LN$Rec) );
              -- Set some properties --
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_LABEL', to_char(LN$Rec) || ',' || :EMP.ENAME );
              If :EMP.JOB = 'MANAGER' Then
                Set_Custom_Property('EMP.BT', LN$Pos, 'SET_FONT', to_char(LN$Rec) || ',Arial,bold,14' );
                Set_Custom_Property('EMP.BT', LN$Pos, 'SET_FGCOLOR', to_char(LN$Rec) || ',0,0,255' );
              End if ;
              If :GLOBAL.I > 250 Then :GLOBAL.I := 5 ;
              Else  :GLOBAL.I := :GLOBAL.I + 5 ;
              End if ;     
              LC$C := To_Char(LN$Rec) || ','
                   || To_Char(255) || ','
                   || To_Char(255-:GLOBAL.I) || ','
                   || To_Char(255-:GLOBAL.I) ;    
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_BGCOLOR', LC$C );
              Synchronize;
         End if ;
    end;When-Create-Record trigger:
    declare
         LN$N    pls_integer ;
         LN$Rec  pls_integer := :system.cursor_record ;
         LC$C    Varchar2(15) ;
    Begin     
         if get_block_property('EMP',TOP_RECORD) > 1 Then
              LN$n := :system.cursor_record - get_block_property('EMP',TOP_RECORD) + 1 ;
         else
              LN$N := :system.cursor_record ;
         end if;
         If LN$N > 0 Then
              Set_Custom_Property('EMP.BT', LN$n, 'SET_LOG', 'true' );
              -- Add the new item --
              Set_Custom_Property('EMP.BT', LN$n, 'SET_NEW_REC', to_char(LN$Rec) );
         End if ;
    end;Post-Query trigger:
    declare
         LN$Pos  pls_integer ;
         LN$Rec  pls_integer := Get_Block_Property('EMP', CURRENT_RECORD) ;
         LN$Max  pls_integer := Get_Block_Property('EMP', RECORDS_DISPLAYED) ;
         LC$C    Varchar2(15) ;
    Begin     
         LN$Pos :=  LN$Rec - (trunc(LN$Rec/LN$Max) * LN$Max) ;
         If LN$Pos = 0 Then LN$Pos := LN$Max ; End if ;
         If LN$Pos > 0 Then
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_LOG', 'true' );
              -- Add the new item --
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_NEW_REC', to_char(LN$Rec) );
              -- Set some properties --
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_LABEL', to_char(LN$Rec) || ',' || :EMP.ENAME );
              If :EMP.JOB = 'MANAGER' Then
                Set_Custom_Property('EMP.BT', LN$Pos, 'SET_FONT', to_char(LN$Rec) || ',Arial,bold,14' );
                Set_Custom_Property('EMP.BT', LN$Pos, 'SET_FGCOLOR', to_char(LN$Rec) || ',0,0,255' );
              End if ;
              If :GLOBAL.I > 250 Then :GLOBAL.I := 5 ;
              Else  :GLOBAL.I := :GLOBAL.I + 5 ;
              End if ;     
              LC$C := To_Char(LN$Rec) || ','
                   || To_Char(255) || ','
                   || To_Char(255-:GLOBAL.I) || ','
                   || To_Char(255-:GLOBAL.I) ;    
              Set_Custom_Property('EMP.BT', LN$Pos, 'SET_BGCOLOR', LC$C );
              Synchronize;
         End if ;
    end;Don't forget to copy the multirecord.jar file in your /forms/java folder, then add it to the archive and archive_jini tags of your /forms/server/formsweb.cfg file.
    Enjoy it,
    Francois

  • Dynamically change column heading without Dashboard Prompt

    Hi All,
    My requirement is change the column heading dynamically in a report. I have achieved this through setting the presentation variable to the dashboard prompt.
    I have 5 columns in the dashboard prompt. Out of these 5 columns, I want to use only 1 column as dashboard prompt.
    But still I want to dynamically change the column heading of the other 4 columns based on the only 1 column selected in the dashboard prompt.
    Is there anyway to achieve this?

    You need to have some logic to change other 4 columns based on 1 selected column.. where you want put that logic?
    BTW: Check these
    http://total-bi.com/2011/03/obiee-dynamic-column-headings/
    http://rampradeeppakalapati.blogspot.com/2012/02/dynamically-change-column-names-in.html
    If helps mark or also update back if you are thru with this.

  • Alignment of dynamically changing StaticText element

    Having a little trouble centering a dynamically changing StaticText element whose parent container has its alignChildren property set to 'center'. As the text of the element changes, new strings that are assigned to it are truncated to the length of the string the element initially held. If I initially place a string of blank characters that is longer in length than any anticiapted text string the element will ever hold, when the text is updated it is offeset to the left by the number of characters of the initial string that are in excess of the length of the string newly assigned to it. Any ideas or suggestions would be very much appreciated.

    Set the initial size of the StaticText with the  "characters" property, which will reserve width so it is the proper width.
    Also set "justify" to "center" so that it will always be centered within that space.
    Note that "characters" is an initial creation property only, and cannot be set after the object has been created.

  • Dynamically changing book index?

    I'm about to start work on a 200+ page manual that is still being edited and added to. I was wondering if there is a way to create a table of contents in which the page numbers dynamically change if content inside the book gets shifted or moved from one page to another.

    jblackz69 wrote:
    I'm about to start work on a 200+ page manual that is still being edited and added to. I was wondering if there is a way to create a table of contents in which the page numbers dynamically change if content inside the book gets shifted or moved from one page to another.
    When you update a table of contents, this is automatic. Look up table of contents in Help.
    HTH
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices

  • Great Challenge !! No one is able to Tell Solution ? Dynamic GUI Updation

    Topic: Dynamic GUI Updation on msWindows when user changes Display properties.
    (I post this Question last month and have't got any answer, Is there no way for this ?)
    I want to dynamicly Update my UI on msWindows when user changes Display properties, Like other windows applications.
    i am doing this procedure-
    1.to get windows look & feel-
    UIManager.getSystemLookAndFeelClassName()
    2.To receive Events when when user changes Display properties-
    Toolkit.getDefaultToolkit().addPropertyChangeListener( "win.desktop.backgroundColor" ,new Java.beans.PropertyChangeListener()
    public void propertyChange(java.beans.PropertyChangeEvent e)
    3.To Reflect it in GUI-
    SwingUtilities.updateComponentTreeUI(TOP COMPONENT);
    But it only reflects the Border & Title Bar of My application.
    pls. suggest what can i do ?
    Regards
    Naveen Sharma

    I seem to remember looking at a similar thing in the Java demos that came with jdk1.3. I could be wrong...
    Let me see...
    Aha! Here it is.
    on my pc the path is
    C:\jdk1.3\demo\jfc\Metalworks
    then click on the jar file. The demo allows you to change the background color, font size on the toolbar etc..Another demo Swingset2 allows you to dynamically change the look and feel. I hope this helps. If you don`t have these demos I could always send you the code.
    Regards
    Grahame

  • How to Update the JTable Content

    Hi Friends
    In my Program i have a Form having a JTable with shows some content on it. Now when the User Click on the Row it will ask where he wants to Edit that rows content. If the User gives Yes. then the Another JDialog opens with the Selected rows Data.
    Now when the User makes changes in the Data and Clicks on the Edit Button. It Should Show the Entered Data on the JTable immediatly.
    I am Posting my working Code. It works fine. But only the Updating the Newly entered Data to the JTable is not done.
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    public class EditTable extends JDialog implements ActionListener,MouseListener
         private JRadioButton rby,rbn,rbr,rbnore,rbnorest;
         private ButtonGroup bg;
         private JPanel exportpanel;
         private JButton btnExpots;
         JTable table;
         JScrollPane scroll;
         public EditTable()throws Exception
              setSize(550,450);
              setTitle("Export Results");
              this.setLocation(100,100);
              String Heading[]={"BOOK ID","NAME","AUTHOR","PRICE"};
              String records[][]={{"B0201","JAVA PROGRAMING","JAMES","1234.00"},
                               {"B0202","SERVLET PROGRAMING","GOSLIN","1425.00"},
                               {"B0203","PHP DEVELOPMENT","SUNITHA","123"},
                               {"B0204","PRIAM","SELVI","1354"},
                               {"B0205","JAVA PROGRAMING","JAMES","1234.00"},
                               {"B0206","SERVLET PROGRAMING","GOSLIN","1425.00"},
                               {"B0207","PHP DEVELOPMENT","SUNITHA","123"},
                               {"B0208","PRIAM","SELVI","1354"}};
              btnExpots= new JButton("Export");
              btnExpots.addActionListener(this);
              btnExpots.setBounds(140,200,60,25);
              table = new JTable();
              table.addMouseListener(this);
              scroll=new JScrollPane(table);
              ((DefaultTableModel)table.getModel()).setDataVector(records,Heading);
              System.out.println(table.getModel());
              exportpanel= new JPanel();
              exportpanel.add(btnExpots,BorderLayout.SOUTH);
              exportpanel.add(scroll);
              getContentPane().add(exportpanel);
              setVisible(true);
          public void actionPerformed(ActionEvent ae)
         public static void main(String arg[]) throws Exception
              EditTable ex= new EditTable();
           public void mouseClicked(MouseEvent me)
              Object obj=me.getSource();
              if(obj==table)
                        JTable source=(JTable)me.getSource();
                        int row = source.rowAtPoint(me.getPoint());
                        int column = source.columnAtPoint(me.getPoint());
                        System.out.println("Working Point"+row+"and"+column);
                        Object value1 = source.getValueAt(row,0);     
                        Object value2 = source.getValueAt(row,1);
                        Object value3 = source.getValueAt(row,2);
                        Object value4 = source.getValueAt(row,3);
                        String bkId=value1.toString();
                        String bkNm=value2.toString();
                        String bkAuthr=value3.toString();
                        String bkAuthrCd=value4.toString();
                        int opt = JOptionPane.showConfirmDialog(this,"Do you Really Want to Edit this Book?","Edit Books",JOptionPane.YES_NO_OPTION);
                        if(opt==JOptionPane.YES_OPTION)
                             try
                                  editForm  editfrm= new editForm ();
                                  editfrm.setVisible(true);
                                  editfrm.setVisible(true);
                                  editfrm.txtbookID.setText(""+bkId);
                                  editfrm.txtbookName.setText(""+bkNm);
                                  editfrm.txtbookAuthorName.setText(""+bkAuthr);
                                  editfrm.txtPrice.setText(""+bkAuthrCd);
                             catch(Exception ex)
                                  ex.printStackTrace();
        public void mousePressed(MouseEvent e) {
        public void mouseReleased(MouseEvent e) {
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
    class editForm extends JDialog implements ActionListener
         JLabel lblbookID,lblbookName,lblbookAuthorName,lblPrice;
         JTextField txtbookID,txtbookName,txtbookAuthorName,txtPrice;
         JButton btnEdit,btnClose;
         JPanel editPanel;
              public editForm()
                   setSize (350,400);
                   this.setTitle("Edit Books");
                   this.setLocation(100,135);
                   lblbookID= new JLabel("Book ID:");
                   lblbookID.setBounds (15, 15, 100, 20);
                   lblbookName= new JLabel("Book Name:");
                   lblbookName.setBounds (15, 45, 100, 20);
                   lblbookAuthorName= new JLabel("Author Name:");
                   lblbookAuthorName.setBounds (15, 75, 100, 20);
                   lblPrice= new JLabel("Price:");
                   lblPrice.setBounds (15, 105, 100, 20);
                   Font fnt = new Font("serif",Font.BOLD,18);
                   txtbookID= new JTextField();
                   txtbookID.setFont(fnt);
                   txtbookID.setEditable(false);
                   txtbookID.setBounds (120, 15, 175, 20);
                   txtbookName= new JTextField();
                   txtbookName.setFont(fnt);
                   txtbookName.setBounds (120, 45, 175, 20);
                   txtbookAuthorName= new JTextField();
                   txtbookAuthorName.setFont(fnt);
                   txtbookAuthorName.setBounds (120, 75, 175, 20);
                   txtPrice= new JTextField();
                   txtPrice.setFont(fnt);
                   txtPrice.setBounds (120, 105, 175, 20);
                   btnEdit = new JButton("Edit");
                   btnEdit.addActionListener(this);
                   btnEdit.setBounds (50, 295, 100, 25);
                   btnEdit.setMnemonic(KeyEvent.VK_E);
                   btnClose= new JButton("Close");
                   btnClose.addActionListener(this);
                   btnClose.setBounds (170, 295, 100, 25);
                   btnClose.setMnemonic(KeyEvent.VK_C);
                   editPanel = new JPanel();
                   editPanel.setLayout(null);
                   editPanel.add(lblbookID);
                   editPanel.add(lblbookName);
                   editPanel.add(lblbookAuthorName);
                   editPanel.add(lblPrice);
                   editPanel.add(txtbookID);
                   editPanel.add(txtbookName);
                   editPanel.add(txtbookAuthorName);
                   editPanel.add(txtPrice);
                   editPanel.add(btnEdit);
                   editPanel.add(btnClose);
                   getContentPane().add(editPanel);
                public void actionPerformed(ActionEvent ae)
    }Could anyone Please Run my code and Help me to Update the JTable Record.
    Thank you for your Help
    Cheers
    Jofin

    Your EditForm needs acces to the TableModel and the current row you are editing. Then when the user clicks the save button you simply use the TableModel.setValueAt(...) method to update the model and the table will be repainted automatically.

  • Dynamic JTreeTable updating

    Hi. I've read all message from swing forum about dynamic JTreeTable updating but didn't find a desision. But now may be i have something.
    May be it's wrong - comments are welcome.
    1. I changed AbstractTreeTableModel
    public abstract class AbstractTreeTableModel extends DefaultTreeModel implements TreeTableModel
    2. removed overrided method getChild, isLeaf ....
    3. remove from JTreeTable
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    if (root.getChildCount() > 0) {
    while(root.getChildCount() > 0){
    TreeNode node = root.getChildAt(0);
    model.removeNodeFromParent((MutableTreeNode) node);
    4. append new nodes
    scfNode = new DefaultMutableTreeNode(new CapacityNode(root, scfName));
    model.insertNodeInto(scfNode, root, root.getChildCount());

    Hello Jay,
    The Fluent UI doesn't provide anything for that.
    The Fluent UI (aka Ribbon UI) is described in depth in the following series of articles in MSDN:
    Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
    Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
    Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

  • Dynamic changes / init file?

    Is there any way to bypass changing the init file to make a dynamic change?
    I have to make a change for archiving, and I can't bounce the db right now.
    10.2.0.3, HPUX itanium
    changes that need to be made...
    log_archive_config DG_CONFIG=(peregrine,swesc)
    log_archive_dest_state_2 = DEFER
    fal_client peregrine
    fal_server swesc
    I don't really want to just issue these at the command line unknowing if they would do as I want or cause adverse affects.
    Is it possible to just rip the command, and update the file too? command line causing immediate change, and init file change will allow for keeping it when restarted...
    Thanks

    alter system set <parameter> = <value>;defaults to memory assuming that they are immediately modifiable
    otherwise
    alter system set <parameter> = <value> scope = memory;should do the trick as well. You probably want to use a spfile that way you can do both at the same time:
    alter system set <parameter> = <value> scope = both;

  • Using DelayQueue with dynamically changing delay times?

    Greetings all:
    First-time poster, so please be gentle. :-)
    I am implementing a cache timer task whose job is to removes idle elements from a cache after x time, and was considering a DelayQueue as potentially more efficient than iterating through the entire cache each time. Important point is that the delay time of elements in the queue will be dynamically changing while they're in the queue, until the point when they become idle, i.e., each time an element's content changes, its expiration time moves further out.
    I went looking in the DelayQueue source (and from there to PriorityQueue) as I was interested to see how it implements its sorting mechanism, and it appears to me that it may not handle this properly. Specifically, it appears that the queue is sorted when elements are added or removed but not otherwise, so that you could end up with the head of the queue being an element that has not really expired.
    Question: Has anyone used a DelayQueue for this kind of scenario, and if so, did it work as expected?
    Thanks,
    Brian

    If you want this behaviour I suggest you look at
    overriding LinkedHashMap as it has a means to
    maintain sorted from most recently accessed to last
    accessed.
    Thus to clear it all you need to do is remove the
    oldest elements.Interesting. Currently I'm using a HashMap so changing to a LinkedHashMap would require virtually no changes to existing code. It still won't quite work as-is, though, because access only gets updated on put's and remove's, whereas I would need access updated on any modification to a contained object as well. I'll think about it a bit more - thanks for the suggestion.

  • Best Practice: Dynamically changing Item-Level permissions?

    Hi all,
    Can you share your opinion on the best practice for Dynamically changing item permissions?
    For example, given this scenario:
    Item Creator can create an initial item.
    After item creator creates, the item becomes read-only for him. Other users can create, but they can only see their own entries (Created by).
    At any point in time, other users can be given Read access (or any other access) by an Administrator to a specific item.
    The item is then given edit permission to a Reviewer and Approver. Reviewers can only edit, and Approvers can only approve.
    After the item has been reviewed, the item becomes read-only to everyone.
    I read that there is only a specific number of unique permissions for a List / Library before performance issues start to set in. Given the requirements above, it looks like item-level permission is unavoidable.
    Do you have certain ideas how best to go with this?
    Thank you!

    Hi,
    According to your post, my understanding is that you wanted to change item level permission.
    There is no out of the box way to accomplish this with SharePoint.               
    You can create a custom permission level using Visual Studio to allow users to add & view items, but not edit permission.   
    Then create a group with the custom permission level. The users in this group would have the permission of create & add permission, but they could no edit the item.
    In the CodePlex, there is a custom workflow activities, but by default it only have four permission level:
    Full Control , Design ,Contribute and Read.
    You should also customize some permission levels for your scenario. 
    What’s more, when use the SharePoint 2013 designer, you should only use the 2010 platform to create the workflow using this activities,
    https://spdactivities.codeplex.com/wikipage?title=Grant%20Permission%20on%20Item
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • How to dynamically change the text of a TextObject with embedded DataField?

    Hi
    I'm trying to dynamically change the text of a TextObject at runtime, by using the .NET library. My problem is that if one or more DatabaseFieldDefinition is embedded inside my text, I'm unable to change the "static text" only, by keeping the field, e.g. I have :
    Text1 => "Contact Name: {Contact.Name}"
    and I'd like to change it to anything else like:
    Text1 => "Nom du Contact: {Contact.Name}"
    Half of my TextObject is static text while second part comes from the dataset.
    (of course the translation is dynamic - it is called at run-time and the new value to be set depends on the calling application language)
    If I simply modify the Text property of my TextObject, the {Contact.Name} embedded field is not evaluated anymore by the Crystal Engine, but considered as a single text.
    Using formulas or parameters looks quite difficult, because it means having many ones just for translation needs - I cannot control the way my users will create their reports and "force them" to use complex methods just in order to put a text and a value together...
    Anyone knows how to deal with that ?

    Only way I can think of doing this:
    1) Create a formula (call it lang) and enter the string "Contact Name" in it
    2) Place the  {Contact.Name} field next to the string
    3) So now you have:
    ContactName:  {Contact.Name}
    4) Check what localization you are after. If you need "Nom du Contact", change the lang formula so it shows "Nom du Contact" using the code below:
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim Report As New CrystalReport1()
    Dim FormulaFields As FormulaFieldDefinitions
    Dim FormulaField As FormulaFieldDefinition
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    FormulaFields = Report.DataDefinition.FormulaFields
    FormulaField = FormulaFields.Item(0)
    FormulaField.Text = "[formula text]"
    CrystalReportViewer1.ReportSource = Report
    End Sub
    I realize this may not give you consistent spacing as the translations may have strings of differnt length. Perhaps someone has other idea(s)...

Maybe you are looking for