Java Code Examples for javax.swing.table.DefaultTableModel#getValueAt()

The following examples show how to use javax.swing.table.DefaultTableModel#getValueAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZettelkastenViewUtil.java    From Zettelkasten with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method updates a jTable and a possible linked list which holds
 * filtered values from the jTables, by completely removing an entry/value
 * from the tablemodel and the linked list.
 * <br><br>
 * If no complete removal is requested, but a decrease in the frequencies,
 * call
 * {@link #updateTableFrequencyDelete(javax.swing.JTable, java.util.LinkedList) updateTableFrequencyDelete(javax.swing.JTable, java.util.LinkedList)}
 * instead.
 *
 * @param table the table were we have to add a new value with frequency
 * @param list the possible linked list were we have to add a new value with
 * frequency
 * @param zettelkastenView
 * @return an updated linked list that was passed as parameter {@code list}
 */
public static LinkedList<Object[]> updateTableFrequencyRemove(JTable table, LinkedList<Object[]> list, ZettelkastenView zettelkastenView) {
    // get table model
    DefaultTableModel dtm = (DefaultTableModel) table.getModel();
    // retrieve selected rows
    int[] rows = table.getSelectedRows();
    for (int cnt = rows.length - 1; cnt >= 0; cnt--) {
        try {
            int selectedrow = table.convertRowIndexToModel(rows[cnt]);
            if (list != null) {
                Object[] o = new Object[2];
                o[0] = dtm.getValueAt(selectedrow, 0);
                o[1] = dtm.getValueAt(selectedrow, 1);
                int pos = findInLinkedList(list, o);
                if (pos != -1) {
                    list.remove(pos);
                }
            }
            dtm.removeRow(selectedrow);
        } catch (ArrayIndexOutOfBoundsException e) {
            Constants.zknlogger.log(Level.WARNING, e.getLocalizedMessage());
        }
    }
    return list;
}
 
Example 2
Source File: QiNiuYunMsgMaker.java    From WePush with MIT License 6 votes vote down vote up
/**
 * 准备(界面字段等)
 */
@Override
public void prepare() {
    templateId = QiNiuYunMsgForm.getInstance().getMsgTemplateIdTextField().getText();

    if (QiNiuYunMsgForm.getInstance().getTemplateMsgDataTable().getModel().getRowCount() == 0) {
        QiNiuYunMsgForm.initTemplateDataTable();
    }

    DefaultTableModel tableModel = (DefaultTableModel) QiNiuYunMsgForm.getInstance().getTemplateMsgDataTable().getModel();
    int rowCount = tableModel.getRowCount();
    paramMap = Maps.newHashMap();
    for (int i = 0; i < rowCount; i++) {
        String key = ((String) tableModel.getValueAt(i, 0));
        String value = ((String) tableModel.getValueAt(i, 1));
        paramMap.put(key, value);
    }
}
 
Example 3
Source File: MainGUI.java    From ciscorouter with MIT License 6 votes vote down vote up
/**
 * Returns a list of hosts to be scanned (factoring in the checkboxes)
 * @return A list of hosts that are "checked" and should be scanned
 */
public ArrayList<Host> getHostsToScan() {
    ArrayList<Host> toScan = new ArrayList<>();
    DefaultTableModel tableModel = (DefaultTableModel) currentConfTable.getModel();
    //By writing the number of rows as currentRow, we won't deal with empty rows!
    int numRows = currentRow;
    for (int i = 0; i < numRows; i++) {
        //If the host is unchecked
        if (!((boolean)tableModel.getValueAt(i, 0))) {
            continue; //Don't bother processing it
        }
        String guiHostname = (String) tableModel.getValueAt(i,1);
        for (Host h : hosts) {
            String hostname = h.toString();
            if (hostname.compareTo(guiHostname) == 0) {
                toScan.add(h);
            }
        }
    }
    return toScan;
}
 
Example 4
Source File: UpYunMsgMaker.java    From WePush with MIT License 6 votes vote down vote up
/**
 * 准备(界面字段等)
 */
@Override
public void prepare() {
    templateId = UpYunMsgForm.getInstance().getMsgTemplateIdTextField().getText();

    if (UpYunMsgForm.getInstance().getTemplateMsgDataTable().getModel().getRowCount() == 0) {
        UpYunMsgForm.initTemplateDataTable();
    }

    DefaultTableModel tableModel = (DefaultTableModel) UpYunMsgForm.getInstance().getTemplateMsgDataTable().getModel();
    int rowCount = tableModel.getRowCount();
    paramList = Lists.newArrayList();
    for (int i = 0; i < rowCount; i++) {
        String value = ((String) tableModel.getValueAt(i, 1));
        paramList.add(value);
    }
}
 
Example 5
Source File: ToDoCustomizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void fireChanged() {
    DefaultTableModel model = (DefaultTableModel) table.getModel();
    ArrayList<String> patterns = new ArrayList<String>(model.getRowCount());
    for (int i = 0; i < model.getRowCount(); i++) {
        Object value = model.getValueAt(i, 0);
        if (value == null) {
            continue;
        }
        String pattern = value.toString();
        //remove empty patterns
        if (!pattern.trim().isEmpty() && !pattern.trim().equals(getDummyPattern())) {
            patterns.add(pattern);
        }
    }
    changed = !id2comments.isEmpty()
            || Settings.getDefault().isScanCommentsOnly() != checkScanCommentsOnly.isSelected()
            || Settings.getDefault().getPatterns().size() != patterns.size()
            || !Settings.getDefault().getPatterns().containsAll(patterns)
            || Settings.getDefault().getExtensionIdentifiers().size() != extensionIdentifiers.size()
            || !Settings.getDefault().getExtensionIdentifiers().containsAll(extensionIdentifiers)
            || Settings.getDefault().getMimeIdentifiers().size() != mimeIdentifiers.size()
            || !Settings.getDefault().getMimeIdentifiers().containsAll(mimeIdentifiers);
}
 
Example 6
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
@Override protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder encoder) {
  super.initialize(type, oldInstance, newInstance, encoder);
  DefaultTableModel m = (DefaultTableModel) oldInstance;
  for (int row = 0; row < m.getRowCount(); row++) {
    for (int col = 0; col < m.getColumnCount(); col++) {
      Object[] o = {m.getValueAt(row, col), row, col};
      encoder.writeStatement(new Statement(oldInstance, "setValueAt", o));
    }
  }
}
 
Example 7
Source File: CSetBibKey.java    From Zettelkasten with GNU General Public License v3.0 5 votes vote down vote up
private void filterList(boolean regEx) {
    // when we filter the table and want to restore it, we don't need to run the
    // time-consuming task that creates the author-list and related author-frequencies.
    // instead, we simply copy the values from the linkedlist to the table-model, which is
    // much faster. but therefore we have to apply all changes to the filtered-table
    // (like adding/changing values in a filtered list) to the linked list as well.

    // get text from the textfield containing the filter string
    // convert to lowercase, we don't want case-sensitive search
    String text = jTextFieldFilterTable.getText().toLowerCase();
    // when we have no text, do nothing
    if (text.isEmpty()) {
        return;
    }
    // get table model
    DefaultTableModel dtm = (DefaultTableModel) jTablePreview.getModel();
    // if we haven't already stored the current complete table data, do this now
    if (null == linkedtablelist) {
        // create new instance of list
        linkedtablelist = new LinkedList<>();
        // go through all table-data
        for (int cnt = 0; cnt < dtm.getRowCount(); cnt++) {
            // init the object-variable
            Object[] o = new Object[2];
            // fill object with values
            o[0] = dtm.getValueAt(jTablePreview.convertRowIndexToModel(cnt), 0);
            o[1] = dtm.getValueAt(jTablePreview.convertRowIndexToModel(cnt), 1);
            // add object to linked list
            linkedtablelist.add(o);
        }
    }
    TableUtils.filterTable(jTablePreview, dtm, text, new int[]{1}, regEx);
    // reset textfield
    jTextFieldFilterTable.setText("");
    jTextFieldFilterTable.requestFocusInWindow();
    // enable textfield only if we have more than 1 element in the jtable
    jTextFieldFilterTable.setEnabled(jTablePreview.getRowCount() > 0);
    // enable refresh button
    jButtonRefreshView.setEnabled(true);
}
 
Example 8
Source File: TableMonitor.java    From DeconvolutionLab2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
	DefaultTableModel model = (DefaultTableModel) table.getModel();
	Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	if (row >= 0) {
		Long id = (Long) model.getValueAt(row, 0);
		Color color = colors.get(id);
		c.setForeground(color);
	}
	return c;
}
 
Example 9
Source File: TablePanel.java    From CodeGen with MIT License 5 votes vote down vote up
public List<Field> getFields() {
    List<Field> fields = new ArrayList<>();
    List<String> ignoreList = new ArrayList<>();
    if (StringUtils.isNotBlank(settingManager.getVariables().getIgnoreFields())) {
        ignoreList = StringUtils.splitToList(settingManager.getVariables().getIgnoreFields(), ",", true);
    }

    DefaultTableModel tableModel = (DefaultTableModel) fieldTable.getModel();
    for (int i = 0; i < tableModel.getRowCount(); i++) {
        Field field = new Field();
        // field
        field.setField(tableModel.getValueAt(i, 0).toString());
        // field.setFieldType(tableModel.getValueAt(i, 1).toString()); // setColumnType设置
        // column and type
        field.setColumn(tableModel.getValueAt(i, 2).toString());
        Object sqlType = tableModel.getValueAt(i, 4);
        if (Objects.nonNull(sqlType)) {
            field.setSqlType(sqlType.toString());
        }
        field.setColumnType(tableModel.getValueAt(i, 3).toString());
        if (Objects.nonNull(tableModel.getValueAt(i, 5))) {
            field.setColumnSize(tableModel.getValueAt(i, 5).toString());
        }
        if (Objects.nonNull(tableModel.getValueAt(i, 6))) {
            field.setComment(tableModel.getValueAt(i, 6).toString());
        }
        // 过滤
        if (!ignoreList.contains(field.getColumn().toUpperCase().trim())) {
            fields.add(field);
        }
    }
    return fields;
}
 
Example 10
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
@Override protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder encoder) {
  super.initialize(type, oldInstance, newInstance, encoder);
  DefaultTableModel m = (DefaultTableModel) oldInstance;
  // Vector v = m.getDataVector();
  // for (int i = 0; i < m.getRowCount(); i++) {
  //   encoder.writeStatement(new Statement(oldInstance, "addRow", new Object[] { (Vector) v.get(i) }));
  // }
  for (int row = 0; row < m.getRowCount(); row++) {
    for (int col = 0; col < m.getColumnCount(); col++) {
      Object[] o = {m.getValueAt(row, col), row, col};
      encoder.writeStatement(new Statement(oldInstance, "setValueAt", o));
    }
  }
}
 
Example 11
Source File: SettingsDialog.java    From megabasterd with GNU General Public License v3.0 4 votes vote down vote up
private void remove_mega_account_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remove_mega_account_buttonActionPerformed

        DefaultTableModel model = (DefaultTableModel) mega_accounts_table.getModel();

        int selected = mega_accounts_table.getSelectedRow();

        while (selected >= 0) {

            String email = (String) model.getValueAt(mega_accounts_table.convertRowIndexToModel(selected), 0);

            _deleted_mega_accounts.add(email);

            model.removeRow(mega_accounts_table.convertRowIndexToModel(selected));

            selected = mega_accounts_table.getSelectedRow();
        }

        mega_accounts_table.clearSelection();

        if (model.getRowCount() == 0) {

            remove_mega_account_button.setEnabled(false);
        }

    }
 
Example 12
Source File: ModeratorsTabActions.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private static String extractUserName(final int rowNum, final DefaultTableModel tableModel) {
  return (String) tableModel.getValueAt(rowNum, 0);
}
 
Example 13
Source File: QiNiuYunMsgForm.java    From WePush with MIT License 4 votes vote down vote up
@Override
public void save(String msgName) {
    int msgId = 0;
    boolean existSameMsg = false;

    List<TMsgSms> tMsgSmsList = msgSmsMapper.selectByMsgTypeAndMsgName(MessageTypeEnum.QI_NIU_YUN_CODE, msgName);
    if (tMsgSmsList.size() > 0) {
        existSameMsg = true;
        msgId = tMsgSmsList.get(0).getId();
    }

    int isCover = JOptionPane.NO_OPTION;
    if (existSameMsg) {
        // 如果存在,是否覆盖
        isCover = JOptionPane.showConfirmDialog(MainWindow.getInstance().getMessagePanel(), "已经存在同名的历史消息,\n是否覆盖?", "确认",
                JOptionPane.YES_NO_OPTION);
    }

    if (!existSameMsg || isCover == JOptionPane.YES_OPTION) {
        String templateId = getInstance().getMsgTemplateIdTextField().getText();

        String now = SqliteUtil.nowDateForSqlite();

        TMsgSms tMsgSms = new TMsgSms();
        tMsgSms.setMsgType(MessageTypeEnum.QI_NIU_YUN_CODE);
        tMsgSms.setMsgName(msgName);
        tMsgSms.setTemplateId(templateId);
        tMsgSms.setCreateTime(now);
        tMsgSms.setModifiedTime(now);

        if (existSameMsg) {
            msgSmsMapper.updateByMsgTypeAndMsgName(tMsgSms);
        } else {
            msgSmsMapper.insertSelective(tMsgSms);
            msgId = tMsgSms.getId();
        }

        // 保存模板数据
        // 如果是覆盖保存,则先清空之前的模板数据
        if (existSameMsg) {
            templateDataMapper.deleteByMsgTypeAndMsgId(MessageTypeEnum.QI_NIU_YUN_CODE, msgId);
        }

        // 如果table为空,则初始化
        if (getInstance().getTemplateMsgDataTable().getModel().getRowCount() == 0) {
            initTemplateDataTable();
        }

        // 逐行读取
        DefaultTableModel tableModel = (DefaultTableModel) getInstance().getTemplateMsgDataTable()
                .getModel();
        int rowCount = tableModel.getRowCount();
        for (int i = 0; i < rowCount; i++) {
            String name = (String) tableModel.getValueAt(i, 0);
            String value = (String) tableModel.getValueAt(i, 1);

            TTemplateData tTemplateData = new TTemplateData();
            tTemplateData.setMsgType(MessageTypeEnum.QI_NIU_YUN_CODE);
            tTemplateData.setMsgId(msgId);
            tTemplateData.setName(name);
            tTemplateData.setValue(value);
            tTemplateData.setCreateTime(now);
            tTemplateData.setModifiedTime(now);

            templateDataMapper.insert(tTemplateData);
        }

        JOptionPane.showMessageDialog(MainWindow.getInstance().getMessagePanel(), "保存成功!", "成功",
                JOptionPane.INFORMATION_MESSAGE);
    }

}
 
Example 14
Source File: BdYunMsgForm.java    From WePush with MIT License 4 votes vote down vote up
@Override
public void save(String msgName) {
    int msgId = 0;
    boolean existSameMsg = false;

    List<TMsgSms> tMsgSmsList = msgSmsMapper.selectByMsgTypeAndMsgName(MessageTypeEnum.BD_YUN_CODE, msgName);
    if (tMsgSmsList.size() > 0) {
        existSameMsg = true;
        msgId = tMsgSmsList.get(0).getId();
    }

    int isCover = JOptionPane.NO_OPTION;
    if (existSameMsg) {
        // 如果存在,是否覆盖
        isCover = JOptionPane.showConfirmDialog(MainWindow.getInstance().getMessagePanel(), "已经存在同名的历史消息,\n是否覆盖?", "确认",
                JOptionPane.YES_NO_OPTION);
    }

    if (!existSameMsg || isCover == JOptionPane.YES_OPTION) {
        String templateId = getInstance().getMsgTemplateIdTextField().getText();

        String now = SqliteUtil.nowDateForSqlite();

        TMsgSms tMsgSms = new TMsgSms();
        tMsgSms.setMsgType(MessageTypeEnum.BD_YUN_CODE);
        tMsgSms.setMsgName(msgName);
        tMsgSms.setTemplateId(templateId);
        tMsgSms.setCreateTime(now);
        tMsgSms.setModifiedTime(now);

        if (existSameMsg) {
            msgSmsMapper.updateByMsgTypeAndMsgName(tMsgSms);
        } else {
            msgSmsMapper.insertSelective(tMsgSms);
            msgId = tMsgSms.getId();
        }

        // 保存模板数据
        // 如果是覆盖保存,则先清空之前的模板数据
        if (existSameMsg) {
            templateDataMapper.deleteByMsgTypeAndMsgId(MessageTypeEnum.BD_YUN_CODE, msgId);
        }

        // 如果table为空,则初始化
        if (getInstance().getTemplateMsgDataTable().getModel().getRowCount() == 0) {
            initTemplateDataTable();
        }

        // 逐行读取
        DefaultTableModel tableModel = (DefaultTableModel) getInstance().getTemplateMsgDataTable()
                .getModel();
        int rowCount = tableModel.getRowCount();
        for (int i = 0; i < rowCount; i++) {
            String name = (String) tableModel.getValueAt(i, 0);
            String value = (String) tableModel.getValueAt(i, 1);

            TTemplateData tTemplateData = new TTemplateData();
            tTemplateData.setMsgType(MessageTypeEnum.BD_YUN_CODE);
            tTemplateData.setMsgId(msgId);
            tTemplateData.setName(name);
            tTemplateData.setValue(value);
            tTemplateData.setCreateTime(now);
            tTemplateData.setModifiedTime(now);

            templateDataMapper.insert(tTemplateData);
        }

        JOptionPane.showMessageDialog(MainWindow.getInstance().getMessagePanel(), "保存成功!", "成功",
                JOptionPane.INFORMATION_MESSAGE);
    }

}
 
Example 15
Source File: MaTemplateMsgForm.java    From WePush with MIT License 4 votes vote down vote up
@Override
public void save(String msgName) {
    int msgId = 0;
    boolean existSameMsg = false;

    List<TMsgMaTemplate> tMsgMaTemplateList = msgMaTemplateMapper.selectByMsgTypeAndMsgName(MessageTypeEnum.MA_TEMPLATE_CODE, msgName);
    if (tMsgMaTemplateList.size() > 0) {
        existSameMsg = true;
        msgId = tMsgMaTemplateList.get(0).getId();
    }

    int isCover = JOptionPane.NO_OPTION;
    if (existSameMsg) {
        // 如果存在,是否覆盖
        isCover = JOptionPane.showConfirmDialog(MainWindow.getInstance().getMessagePanel(), "已经存在同名的历史消息,\n是否覆盖?", "确认",
                JOptionPane.YES_NO_OPTION);
    }

    if (!existSameMsg || isCover == JOptionPane.YES_OPTION) {
        String templateId = getInstance().getMsgTemplateIdTextField().getText();
        String templateUrl = getInstance().getMsgTemplateUrlTextField().getText();
        String templateKeyWord = getInstance().getMsgTemplateKeyWordTextField().getText();

        String now = SqliteUtil.nowDateForSqlite();

        TMsgMaTemplate tMsgMaTemplate = new TMsgMaTemplate();
        tMsgMaTemplate.setMsgType(MessageTypeEnum.MA_TEMPLATE_CODE);
        tMsgMaTemplate.setMsgName(msgName);
        tMsgMaTemplate.setTemplateId(templateId);
        tMsgMaTemplate.setPage(templateUrl);
        tMsgMaTemplate.setEmphasisKeyword(templateKeyWord);
        tMsgMaTemplate.setCreateTime(now);
        tMsgMaTemplate.setModifiedTime(now);

        if (existSameMsg) {
            msgMaTemplateMapper.updateByMsgTypeAndMsgName(tMsgMaTemplate);
        } else {
            msgMaTemplateMapper.insertSelective(tMsgMaTemplate);
            msgId = tMsgMaTemplate.getId();
        }

        // 保存模板数据

        // 如果是覆盖保存,则先清空之前的模板数据
        if (existSameMsg) {
            templateDataMapper.deleteByMsgTypeAndMsgId(MessageTypeEnum.MA_TEMPLATE_CODE, msgId);
        }

        // 如果table为空,则初始化
        if (getInstance().getTemplateMsgDataTable().getModel().getRowCount() == 0) {
            initTemplateDataTable();
        }

        // 逐行读取
        DefaultTableModel tableModel = (DefaultTableModel) getInstance().getTemplateMsgDataTable()
                .getModel();
        int rowCount = tableModel.getRowCount();
        for (int i = 0; i < rowCount; i++) {
            String name = (String) tableModel.getValueAt(i, 0);
            String value = (String) tableModel.getValueAt(i, 1);
            String color = ((String) tableModel.getValueAt(i, 2)).trim();

            TTemplateData tTemplateData = new TTemplateData();
            tTemplateData.setMsgType(MessageTypeEnum.MA_TEMPLATE_CODE);
            tTemplateData.setMsgId(msgId);
            tTemplateData.setName(name);
            tTemplateData.setValue(value);
            tTemplateData.setColor(color);
            tTemplateData.setCreateTime(now);
            tTemplateData.setModifiedTime(now);

            templateDataMapper.insert(tTemplateData);
        }

        JOptionPane.showMessageDialog(MainWindow.getInstance().getMessagePanel(), "保存成功!", "成功",
                JOptionPane.INFORMATION_MESSAGE);
    }
}
 
Example 16
Source File: HwYunMsgForm.java    From WePush with MIT License 4 votes vote down vote up
@Override
public void save(String msgName) {
    int msgId = 0;
    boolean existSameMsg = false;

    List<TMsgSms> tMsgSmsList = msgSmsMapper.selectByMsgTypeAndMsgName(MessageTypeEnum.HW_YUN_CODE, msgName);
    if (tMsgSmsList.size() > 0) {
        existSameMsg = true;
        msgId = tMsgSmsList.get(0).getId();
    }

    int isCover = JOptionPane.NO_OPTION;
    if (existSameMsg) {
        // 如果存在,是否覆盖
        isCover = JOptionPane.showConfirmDialog(MainWindow.getInstance().getMessagePanel(), "已经存在同名的历史消息,\n是否覆盖?", "确认",
                JOptionPane.YES_NO_OPTION);
    }

    if (!existSameMsg || isCover == JOptionPane.YES_OPTION) {
        String templateId = getInstance().getMsgTemplateIdTextField().getText();

        String now = SqliteUtil.nowDateForSqlite();

        TMsgSms tMsgSms = new TMsgSms();
        tMsgSms.setMsgType(MessageTypeEnum.HW_YUN_CODE);
        tMsgSms.setMsgName(msgName);
        tMsgSms.setTemplateId(templateId);
        tMsgSms.setCreateTime(now);
        tMsgSms.setModifiedTime(now);

        if (existSameMsg) {
            msgSmsMapper.updateByMsgTypeAndMsgName(tMsgSms);
        } else {
            msgSmsMapper.insertSelective(tMsgSms);
            msgId = tMsgSms.getId();
        }

        // 保存模板数据
        // 如果是覆盖保存,则先清空之前的模板数据
        if (existSameMsg) {
            templateDataMapper.deleteByMsgTypeAndMsgId(MessageTypeEnum.HW_YUN_CODE, msgId);
        }

        // 如果table为空,则初始化
        if (getInstance().getTemplateMsgDataTable().getModel().getRowCount() == 0) {
            initTemplateDataTable();
        }

        // 逐行读取
        DefaultTableModel tableModel = (DefaultTableModel) getInstance().getTemplateMsgDataTable()
                .getModel();
        int rowCount = tableModel.getRowCount();
        for (int i = 0; i < rowCount; i++) {
            String name = (String) tableModel.getValueAt(i, 0);
            String value = (String) tableModel.getValueAt(i, 1);

            TTemplateData tTemplateData = new TTemplateData();
            tTemplateData.setMsgType(MessageTypeEnum.HW_YUN_CODE);
            tTemplateData.setMsgId(msgId);
            tTemplateData.setName(name);
            tTemplateData.setValue(value);
            tTemplateData.setCreateTime(now);
            tTemplateData.setModifiedTime(now);

            templateDataMapper.insert(tTemplateData);
        }

        JOptionPane.showMessageDialog(MainWindow.getInstance().getMessagePanel(), "保存成功!", "成功",
                JOptionPane.INFORMATION_MESSAGE);
    }

}
 
Example 17
Source File: DSWorkbenchSettingsDialog.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
private void fireOkEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireOkEvent
    if (!jOKButton.isEnabled()) {
        return;
    }
    try {
        /*
          Validate player settings
         */
        UserProfile selectedProfile = null;
        try {
            selectedProfile = (UserProfile) jProfileBox.getSelectedItem();
        } catch (Exception ignored) {
        }
        if (selectedProfile != null) {
            if (selectedProfile.getTribe() == null) {
                //probably data is not loaded yet as there was an error during initialization...just return
                setBlocking(false);
                setVisible(false);
                return;
            }
            if (selectedProfile.getTribe().equals(InvalidTribe.getSingleton())) {
                JOptionPaneHelper.showWarningBox(this, "Der Spieler des gewählten Profils existiert nicht mehr.\nBitte ein anderes Profil wählen. ", "Warnung");
                return;
            }

            logger.debug("Setting default profile for server '" + GlobalOptions.getSelectedServer() + "' to " + selectedProfile.getTribeName());
            UserProfile formerProfile = GlobalOptions.getSelectedProfile();

            if (formerProfile.getProfileId() != selectedProfile.getProfileId()) {
                logger.info("Writing user data for former profile");
                TacticsPlanerWizard.storeProperties();
                ResourceDistributorWizard.storeProperties();
                GlobalOptions.saveUserData();
                GlobalOptions.addProperty("selected.profile", Long.toString(selectedProfile.getProfileId()));
                formerProfile.updateProperties();
                formerProfile.storeProfileData();
                GlobalOptions.setSelectedProfile(selectedProfile);
                logger.info("Loading user data for selected profile");
                GlobalOptions.loadUserData();
            } else {
                GlobalOptions.addProperty("selected.profile", Long.toString(selectedProfile.getProfileId()));
                GlobalOptions.setSelectedProfile(selectedProfile);
            }
        } else if (GlobalOptions.getSelectedProfile() == null) {
            JOptionPaneHelper.showWarningBox(DSWorkbenchSettingsDialog.this, "Du musst ein Profil auswählen um fortzufahren", "Warnung");
            return;
        }

        /*
          Update attack vector colors
         */
        DefaultTableModel model = ((DefaultTableModel) jAttackColorTable.getModel());
        for (int i = 0; i < model.getRowCount(); i++) {
            String unit = ((UnitHolder) model.getValueAt(i, 0)).getName();
            Color color = (Color) model.getValueAt(i, 1);
            String hexCol = Integer.toHexString(color.getRGB());
            hexCol = "#" + hexCol.substring(2, hexCol.length());
            GlobalOptions.addProperty(unit + ".color", hexCol);
        }

        /*
          Validate misc properties
         */
        int sortType = jVillageSortTypeChooser.getSelectedIndex();
        Village.setOrderType(sortType);
        GlobalOptions.addProperty("village.order", Integer.toString(sortType));
        GlobalOptions.addProperty("notify.duration", Integer.toString(jNotifyDurationBox.getSelectedIndex()));
        GlobalOptions.addProperty("inform.on.updates", Boolean.toString(jInformOnUpdates.isSelected()));
        GlobalOptions.addProperty("show.popup.moral", Boolean.toString(jShowPopupMoral.isSelected()));
        GlobalOptions.addProperty("show.popup.conquers", Boolean.toString(jShowPopupConquers.isSelected()));
        GlobalOptions.addProperty("show.popup.ranks", Boolean.toString(jShowPopupRanks.isSelected()));
        GlobalOptions.addProperty("show.popup.farm.space", Boolean.toString(jShowPopupFarmSpace.isSelected()));
        GlobalOptions.addProperty("max.farm.space", jMaxFarmSpace.getText());
        GlobalOptions.addProperty("farm.popup.use.real", Boolean.toString(jPopupFarmUseRealValues.isSelected()));
        GlobalOptions.addProperty("max.density.troops", jMaxTroopDensity.getText());
        GlobalOptions.addProperty("show.live.countdown", Boolean.toString(jShowLiveCountdown.isSelected()));
        GlobalOptions.addProperty("extended.attack.vectors", Boolean.toString(jExtendedAttackLineDrawing.isSelected()));
        GlobalOptions.addProperty("max.sim.rounds", jMaxSimRounds.getText());
        GlobalOptions.addProperty("support.tolerance", jTolerance.getText());
        GlobalOptions.addProperty("max.loss.ratio", jMaxLossRatio.getText());
        GlobalOptions.addProperty("map.marker.transparency", Integer.toString(jMarkerTransparency.getValue()));
        GlobalOptions.addProperty("obst.server", jObstServer.getText());
        GlobalOptions.saveProperties();
        if (!checkSettings()) {
            logger.error("Failed to check server settings");
            return;
        }
        setBlocking(false);
        setVisible(false);
        DSWorkbenchMainFrame.getSingleton().serverSettingsChangedEvent();
        MapPanel.getSingleton().getMapRenderer().initiateRedraw(MapRenderer.ALL_LAYERS);
        MinimapPanel.getSingleton().redraw();
    } catch (Throwable t) {
        logger.error("Failed to close settings dialog", t);
    }
}
 
Example 18
Source File: TxYunMsgForm.java    From WePush with MIT License 4 votes vote down vote up
@Override
public void save(String msgName) {
    int msgId = 0;
    boolean existSameMsg = false;

    List<TMsgSms> tMsgSmsList = msgSmsMapper.selectByMsgTypeAndMsgName(MessageTypeEnum.TX_YUN_CODE, msgName);
    if (tMsgSmsList.size() > 0) {
        existSameMsg = true;
        msgId = tMsgSmsList.get(0).getId();
    }

    int isCover = JOptionPane.NO_OPTION;
    if (existSameMsg) {
        // 如果存在,是否覆盖
        isCover = JOptionPane.showConfirmDialog(MainWindow.getInstance().getMessagePanel(), "已经存在同名的历史消息,\n是否覆盖?", "确认",
                JOptionPane.YES_NO_OPTION);
    }

    if (!existSameMsg || isCover == JOptionPane.YES_OPTION) {
        String templateId = getInstance().getMsgTemplateIdTextField().getText();

        String now = SqliteUtil.nowDateForSqlite();

        TMsgSms tMsgSms = new TMsgSms();
        tMsgSms.setMsgType(MessageTypeEnum.TX_YUN_CODE);
        tMsgSms.setMsgName(msgName);
        tMsgSms.setTemplateId(templateId);
        tMsgSms.setCreateTime(now);
        tMsgSms.setModifiedTime(now);

        if (existSameMsg) {
            msgSmsMapper.updateByMsgTypeAndMsgName(tMsgSms);
        } else {
            msgSmsMapper.insertSelective(tMsgSms);
            msgId = tMsgSms.getId();
        }

        // 保存模板数据
        // 如果是覆盖保存,则先清空之前的模板数据
        if (existSameMsg) {
            templateDataMapper.deleteByMsgTypeAndMsgId(MessageTypeEnum.TX_YUN_CODE, msgId);
        }

        // 如果table为空,则初始化
        if (getInstance().getTemplateMsgDataTable().getModel().getRowCount() == 0) {
            initTemplateDataTable();
        }

        // 逐行读取
        DefaultTableModel tableModel = (DefaultTableModel) getInstance().getTemplateMsgDataTable()
                .getModel();
        int rowCount = tableModel.getRowCount();
        for (int i = 0; i < rowCount; i++) {
            String name = (String) tableModel.getValueAt(i, 0);
            String value = (String) tableModel.getValueAt(i, 1);

            TTemplateData tTemplateData = new TTemplateData();
            tTemplateData.setMsgType(MessageTypeEnum.TX_YUN_CODE);
            tTemplateData.setMsgId(msgId);
            tTemplateData.setName(name);
            tTemplateData.setValue(value);
            tTemplateData.setCreateTime(now);
            tTemplateData.setModifiedTime(now);

            templateDataMapper.insert(tTemplateData);
        }

        JOptionPane.showMessageDialog(MainWindow.getInstance().getMessagePanel(), "保存成功!", "成功",
                JOptionPane.INFORMATION_MESSAGE);
    }

}
 
Example 19
Source File: SettingsDialog.java    From megabasterd with GNU General Public License v3.0 4 votes vote down vote up
private void remove_elc_account_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remove_elc_account_buttonActionPerformed

        DefaultTableModel model = (DefaultTableModel) elc_accounts_table.getModel();

        int selected = elc_accounts_table.getSelectedRow();

        while (selected >= 0) {

            String host = (String) model.getValueAt(elc_accounts_table.convertRowIndexToModel(selected), 0);

            _deleted_elc_accounts.add(host);

            model.removeRow(elc_accounts_table.convertRowIndexToModel(selected));

            selected = elc_accounts_table.getSelectedRow();
        }

        elc_accounts_table.clearSelection();

        if (model.getRowCount() == 0) {

            remove_elc_account_button.setEnabled(false);
        }
    }
 
Example 20
Source File: Action.java    From templatespider with Apache License 2.0 4 votes vote down vote up
/**
	 * 替换模版页面中的动态标签
	 * 1.替换title标签
	 * 2.删除keywords 、 description
	 */
	public static void replaceDongtaiTag(){
		/*
		 * 遍历出模版页面
		 */
		List<Map<String, String>> templatePageList = new ArrayList<Map<String,String>>();
		
		DefaultTableModel pageModel = Global.mainUI.getTemplatePageTableModel();
		int pageRowCount = pageModel.getRowCount();
		for (int i = 0; i < pageRowCount; i++) {
			Map<String, String> map = new HashMap<String, String>();
			//模版页面名字
			String name = (String) pageModel.getValueAt(i, 0);
			if(name != null && name.length() > 0){
				
				Template temp = Global.templateMap.get(name);
				if(temp != null){
					//有这个模版页面
					Document doc = temp.getDoc();
					
					//删除 keywords 、 description
					Elements metaEles = doc.getElementsByTag("meta");
					Iterator<Element> it = metaEles.iterator();
					while(it.hasNext()){
						Element metaEle = it.next();
						String metaName = metaEle.attr("name");
						if(metaEle != null && metaName != null){
							if(metaName.equalsIgnoreCase("keywords") || metaName.equalsIgnoreCase("description")){
								try {
									metaEle.remove();
									it.remove();
								} catch (Exception e) {
									e.printStackTrace();
									System.out.println(metaEle);
								}
							}
						}
					}
					
					//替换title标签
					Elements titleEles = doc.getElementsByTag("title");
					Element titleEle = null;
					if(titleEles != null && titleEles.size() > 0){
						titleEle = titleEles.first();
					}else{
						//若没有这个title,那么需要新增加一个
						Elements headElements = doc.getElementsByTag("head");
						if(headElements == null || headElements.size() == 0){
							UI.showMessageDialog("模版页面"+temp.getFile().getName()+"中无head标签!模版页估计不完整!请手动补上head标签");
							return;
						}else{
//							titleEle = new Element(tag, baseUri)
//							headElements.first().appendElement(tagName)
							/*
							 * 待加入
							 */
						}
					}
					if(titleEle != null){
						//替换title标签为动态标签
						String type = (String) pageModel.getValueAt(i, 1);
						switch (type) {
						case "首页模版":
							titleEle.text(site_name);
							break;
						case "列表页模版":
							titleEle.text(siteColumn_name+"_"+site_name);
							break;
						case "详情页模版":
							titleEle.text(news_title+"_"+site_name);
							break;
						default:
							titleEle.text(site_name);
							break;
						}
					}
					
					Global.templateMap.put(temp.getFile().getName(), temp);
				}
			}
		}
	}