Example usage for org.apache.commons.lang StringUtils defaultString

List of usage examples for org.apache.commons.lang StringUtils defaultString

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultString.

Prototype

public static String defaultString(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is null, the value of defaultStr.

Usage

From source file:info.magnolia.templating.jsp.taglib.SimpleNavigationTag.java

/**
 * Draws page children as an unordered list.
 * //  w  ww . jav a 2 s.  co m
 * @param page current page
 * @param activePage active page
 * @param out jsp writer
 * @throws IOException jspwriter exception
 * @throws RepositoryException any exception thrown during repository reading
 */
private void drawChildren(Content page, Content activePage, JspWriter out)
        throws IOException, RepositoryException {

    Collection<Content> children = new ArrayList<Content>(page.getChildren(ItemType.CONTENT));

    if (children.size() == 0) {
        return;
    }

    out.print("<ul class=\"level");
    out.print(page.getLevel());
    if (style != null && page.getLevel() == startLevel) {
        out.print(" ");
        out.print(style);
    }
    out.print("\">");

    Iterator<Content> iter = children.iterator();
    // loop through all children and discard those we don't want to display
    while (iter.hasNext()) {
        final Content child = iter.next();

        if (expandAll.equalsIgnoreCase(EXPAND_NONE) || expandAll.equalsIgnoreCase(EXPAND_SHOW)) {
            if (child.getNodeData(StringUtils.defaultString(this.hideInNav, DEFAULT_HIDEINNAV_NODEDATA))
                    .getBoolean()) {
                iter.remove();
                continue;
            }
            // use a filter
            if (filter != null) {
                if (!filter.accept(child)) {
                    iter.remove();
                    continue;
                }
            }
        } else {
            if (child.getNodeData(StringUtils.defaultString(this.hideInNav, DEFAULT_HIDEINNAV_NODEDATA))
                    .getBoolean()) {
                iter.remove();
                continue;
            }
        }
    }

    boolean isFirst = true;
    Iterator<Content> visibleIt = children.iterator();
    while (visibleIt.hasNext()) {
        Content child = visibleIt.next();
        List<String> cssClasses = new ArrayList<String>(4);

        NodeData nodeData = I18nContentSupportFactory.getI18nSupport().getNodeData(child,
                NODEDATA_NAVIGATIONTITLE);
        String title = null;
        if (nodeData != null) {
            title = nodeData.getString(StringUtils.EMPTY);
        }

        // if nav title is not set, the main title is taken
        if (StringUtils.isEmpty(title)) {
            title = child.getTitle();
        }

        // if main title is not set, the name of the page is taken
        if (StringUtils.isEmpty(title)) {
            title = child.getName();
        }

        boolean showChildren = false;
        boolean self = false;

        if (!expandAll.equalsIgnoreCase(EXPAND_NONE)) {
            showChildren = true;
        }

        if (activePage.getHandle().equals(child.getHandle())) {
            // self
            showChildren = true;
            self = true;
            cssClasses.add(CSS_LI_ACTIVE);
        } else if (!showChildren) {
            showChildren = child.getLevel() <= activePage.getAncestors().size() && StringUtils
                    .equals(activePage.getAncestor(child.getLevel()).getHandle(), child.getHandle());
        }

        if (!showChildren) {
            showChildren = child
                    .getNodeData(StringUtils.defaultString(this.openMenu, DEFAULT_OPENMENU_NODEDATA))
                    .getBoolean();
        }

        if (endLevel > 0) {
            showChildren &= child.getLevel() < endLevel;
        }

        cssClasses.add(hasVisibleChildren(child) ? showChildren ? CSS_LI_OPEN : CSS_LI_CLOSED : CSS_LI_LEAF);

        if (child.getLevel() < activePage.getLevel()
                && activePage.getAncestor(child.getLevel()).getHandle().equals(child.getHandle())) {
            cssClasses.add(CSS_LI_TRAIL);
        }

        if (StringUtils.isNotEmpty(classProperty) && child.hasNodeData(classProperty)) {
            cssClasses.add(child.getNodeData(classProperty).getString(StringUtils.EMPTY));
        }

        if (markFirstAndLastElement && isFirst) {
            cssClasses.add(CSS_LI_FIRST);
            isFirst = false;
        }

        if (markFirstAndLastElement && !visibleIt.hasNext()) {
            cssClasses.add(CSS_LI_LAST);
        }

        StringBuffer css = new StringBuffer(cssClasses.size() * 10);
        Iterator<String> iterator = cssClasses.iterator();
        while (iterator.hasNext()) {
            css.append(iterator.next());
            if (iterator.hasNext()) {
                css.append(" ");
            }
        }

        out.print("<li class=\"");
        out.print(css.toString());
        out.print("\">");

        if (self) {
            out.println("<strong>");
        }

        String accesskey = null;
        if (child.getNodeData(NODEDATA_ACCESSKEY) != null) {
            accesskey = child.getNodeData(NODEDATA_ACCESSKEY).getString(StringUtils.EMPTY);
        }

        out.print("<a href=\"");
        out.print(((HttpServletRequest) this.pageContext.getRequest()).getContextPath());
        out.print(I18nContentSupportFactory.getI18nSupport().toI18NURI(child.getHandle()));
        out.print(".html\"");

        if (StringUtils.isNotEmpty(accesskey)) {
            out.print(" accesskey=\"");
            out.print(accesskey);
            out.print("\"");
        }

        if (nofollow != null && child.getNodeData(this.nofollow).getBoolean()) {
            out.print(" rel=\"nofollow\"");
        }

        out.print(">");

        if (StringUtils.isNotEmpty(this.wrapperElement)) {
            out.print("<" + this.wrapperElement + ">");
        }

        out.print(StringEscapeUtils.escapeHtml(title));

        if (StringUtils.isNotEmpty(this.wrapperElement)) {
            out.print("</" + this.wrapperElement + ">");
        }

        out.print(" </a>");

        if (self) {
            out.println("</strong>");
        }

        if (showChildren) {
            drawChildren(child, activePage, out);
        }
        out.print("</li>");
    }

    out.print("</ul>");
}

From source file:com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource.java

@Deprecated
@Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
@CheckForNull// w  w  w .  j  a v a 2  s . co  m
public String getCheckoutCredentialsId() {
    for (SCMSourceTrait t : traits) {
        if (t instanceof SSHCheckoutTrait) {
            return StringUtils.defaultString(((SSHCheckoutTrait) t).getCredentialsId(),
                    DescriptorImpl.ANONYMOUS);
        }
    }
    return DescriptorImpl.SAME;
}

From source file:com.benfante.minimark.blo.AssessmentXMLFOBuilder.java

private StringBuilder makeQuestion(StringBuilder result, OpenQuestionFilling question, int order,
        Locale locale) {/*from  w w w  .  java  2 s  .  c  o  m*/
    final String answer = StringUtils.defaultString(question.getAnswer(), " ");
    if (OpenQuestion.VISUALIZATION_LONG.equals(question.getVisualization())) {
        result.append("<fo:table-row>").append('\n');
        result.append("  <fo:table-cell>").append('\n');
        result.append("    <fo:block font-weight=\"bold\">")
                .append(messageSource.getMessage("Question", null, "?Question?", locale)).append(' ')
                .append(order).append("</fo:block>").append('\n');
        result.append("    <fo:block font-weight=\"bold\">").append(question.getTitle()).append("</fo:block>")
                .append('\n');
        result.append("  </fo:table-cell>").append('\n');
        result.append("  <fo:table-cell>").append('\n');
        result.append("    <fo:block>").append('\n');
        result.append(new HTMLFOConverter().convert(question.getFilteredContent())).append('\n');
        result.append("    </fo:block>").append('\n');
        result.append(
                "    <fo:block border-color=\"black\" border-style=\"solid\" white-space-collapse=\"false\" linefeed-treatment=\"preserve\" white-space-treatment=\"preserve\"><![CDATA[")
                .append(answer).append("\n\n").append("]]></fo:block>").append('\n');
        result.append("  </fo:table-cell>").append('\n');
        result.append("</fo:table-row>").append('\n');
    } else {
        result.append("<fo:table-row>").append('\n');
        result.append("  <fo:table-cell>").append('\n');
        result.append("    <fo:block font-weight=\"bold\">")
                .append(messageSource.getMessage("Question", null, "?Question?", locale)).append(' ')
                .append(order).append("</fo:block>").append('\n');
        result.append("    <fo:block font-weight=\"bold\">").append(question.getTitle()).append("</fo:block>")
                .append('\n');
        result.append("  </fo:table-cell>").append('\n');
        result.append("  <fo:table-cell>").append('\n');
        result.append("    <fo:block>").append('\n');
        result.append(new HTMLFOConverter().convert(question.getFilteredContent())).append('\n');
        result.append("    </fo:block>").append('\n');
        result.append(
                "    <fo:block border-color=\"black\" border-style=\"solid\" white-space-collapse=\"false\" linefeed-treatment=\"preserve\" white-space-treatment=\"preserve\"><![CDATA[")
                .append(answer).append("]]></fo:block>").append('\n');
        result.append("  </fo:table-cell>").append('\n');
        result.append("</fo:table-row>").append('\n');
    }
    return result;
}

From source file:com.flexive.cmis.spi.FlexiveFolder.java

protected void processAdd() throws FxApplicationException {
    if (toAdd == null) {
        return;/*from w w  w  .j  av  a 2 s .c om*/
    }
    final FxTreeNode node = getNodeWithChildren(getNode());
    for (CMISObject object : toAdd) {
        checkUniqueName(node, object.getName());
        getTreeEngine().save(FxTreeNodeEdit.createNew(StringUtils.defaultString(object.getName(), ""))
                .setParentNodeId(getNodeId()).setReference(SPIUtils.getDocumentId(object.getId())));
    }
    toAdd.clear();
}

From source file:com.flexive.shared.value.BinaryDescriptor.java

/**
 * Getter for the mime type (if available)
 *
 * @return mime type (if available)/*from w w w  .  j  a v  a 2s.c  o m*/
 */
public String getMimeType() {
    return StringUtils.defaultString(mimeType, MIME_TYPE_UNKNOWN);
}

From source file:info.magnolia.templating.jsp.taglib.SimpleNavigationTag.java

/**
 * Checks if the page has a visible children. Pages with the <code>hide in nav</code> attribute set to <code>true</code> are ignored.
 * //ww w .j  ava2s .co m
 * @param page root page
 * @return <code>true</code> if the given page has at least one visible child.
 */
private boolean hasVisibleChildren(Content page) {
    Collection<Content> children = page.getChildren();
    if (children.size() > 0 && expandAll.equalsIgnoreCase(EXPAND_ALL)) {
        return true;
    }
    for (Content ch : children) {
        if (!ch.getNodeData(StringUtils.defaultString(this.hideInNav, DEFAULT_HIDEINNAV_NODEDATA))
                .getBoolean()) {
            return true;
        }
    }
    return false;
}

From source file:gtu.zcognos.DimensionUI.java

private void initGUI() {
    try {//from   w  ww  .  ja  v  a  2s.c  o m

        final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);
        {
            GroupLayout thisLayout = new GroupLayout((JComponent) getContentPane());
            getContentPane().setLayout(thisLayout);
            this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            {
                projectId = new JTextField();
            }
            {
                jLabel1 = new JLabel();
                jLabel1.setText("PROJECT_ID");
            }
            {
                create = new JButton();
                create.setText("create");
                create.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("create.actionPerformed", evt);
                    }
                });
            }
            {
                reportId = new JTextField();
            }
            {
                jLabel8 = new JLabel();
                jLabel8.setText("report id");
            }
            {
                addDimensionFromDb = new JButton();
                addDimensionFromDb.setText("add from db");
                addDimensionFromDb.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("addFromDb.actionPerformed", evt);
                    }
                });
            }
            {
                dataSourceTable = new JTextField();
                dataSourceTable.setText("rscdpg0901");
            }
            {
                jLabel7 = new JLabel();
                jLabel7.setText("data source table");
            }
            {
                addDimension = new JButton();
                addDimension.setText("add");
                addDimension.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("add.actionPerformed", evt);
                    }
                });
            }
            {
                dimensionName = new JTextField();
            }
            {
                jLabel6 = new JLabel();
                jLabel6.setText("dimension chinese name");
            }
            {
                jLabel5 = new JLabel();
                jLabel5.setText("rscdzzzz id index");
            }
            {
                String[] idx = new String[20];
                for (int ii = 0; ii < idx.length; ii++) {
                    idx[ii] = "id" + (ii + 1);
                }
                ComboBoxModel rscdzzzzIdIndexModel = new DefaultComboBoxModel(idx);
                rscdzzzzIdIndex = new JComboBox();
                rscdzzzzIdIndex.setModel(rscdzzzzIdIndexModel);
            }
            {
                jLabel3 = new JLabel();
                jLabel3.setText("Dimension");
            }
            {
                jScrollPane1 = new JScrollPane();
                {
                    DefaultListModel dimensionListModel = new DefaultListModel();
                    dimensionList = new JList();
                    jScrollPane1.setViewportView(dimensionList);
                    dimensionList.setModel(dimensionListModel);
                    dimensionList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            JListUtil.newInstance(dimensionList).defaultJListKeyPressed(evt);
                        }
                    });
                }
            }
            {
                exportDir = new JButton();
                exportDir.setText("export dir");
                exportDir.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("exportDir.actionPerformed", evt);
                    }
                });
            }
            {
                category = new JTextField();
            }
            {
                jLabel4 = new JLabel();
                jLabel4.setText("category");
            }
            {
                tableName = new JTextField();
            }
            {
                jLabel2 = new JLabel();
                jLabel2.setText("merge table name");
            }
            thisLayout
                    .setHorizontalGroup(thisLayout.createSequentialGroup().addContainerGap(12, 12)
                            .addGroup(thisLayout.createParallelGroup()
                                    .addComponent(jLabel3, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 196, GroupLayout.PREFERRED_SIZE)
                                    .addGroup(thisLayout.createSequentialGroup().addGap(19).addGroup(thisLayout
                                            .createParallelGroup().addGroup(thisLayout.createSequentialGroup()
                                                    .addComponent(exportDir, GroupLayout.PREFERRED_SIZE, 119,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(
                                                            addDimension, GroupLayout.PREFERRED_SIZE, 119,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                                    .addGroup(thisLayout.createParallelGroup().addComponent(
                                                            addDimensionFromDb, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 191,
                                                            GroupLayout.PREFERRED_SIZE)
                                                            .addGroup(thisLayout.createSequentialGroup().addGap(
                                                                    88)
                                                                    .addComponent(create,
                                                                            GroupLayout.PREFERRED_SIZE, 119,
                                                                            GroupLayout.PREFERRED_SIZE))))
                                            .addGroup(thisLayout.createSequentialGroup().addGroup(thisLayout
                                                    .createParallelGroup()
                                                    .addComponent(jLabel6, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel5, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel4, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel8, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel2, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel7, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel1, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE))
                                                    .addGap(39)
                                                    .addGroup(thisLayout.createParallelGroup()
                                                            .addComponent(dimensionName,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(rscdzzzzIdIndex,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(category,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(reportId,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(tableName,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(dataSourceTable,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(projectId,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)))
                                            .addComponent(jScrollPane1, GroupLayout.Alignment.LEADING,
                                                    GroupLayout.PREFERRED_SIZE, 436,
                                                    GroupLayout.PREFERRED_SIZE))))
                            .addContainerGap(11, 11));
            thisLayout.setVerticalGroup(thisLayout.createSequentialGroup().addContainerGap(12, 12)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(projectId, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(dataSourceTable, GroupLayout.Alignment.BASELINE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(tableName, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(reportId, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(category, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup()
                            .addComponent(jLabel5, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(rscdzzzzIdIndex, GroupLayout.Alignment.LEADING,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(dimensionName, GroupLayout.Alignment.BASELINE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(addDimension, GroupLayout.Alignment.BASELINE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(exportDir, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(addDimensionFromDb, GroupLayout.Alignment.BASELINE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE))
                    .addGap(11)
                    .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 269, GroupLayout.PREFERRED_SIZE)
                    .addGap(12).addComponent(create, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(9, 9));
        }
        this.setSize(513, 632);

        swingUtil.addAction("exportDir.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                        .getApproveSelectedFile();
                if (file != null) {
                    baseDir = file;
                }
            }
        });

        swingUtil.addAction("addFromDb.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                String project = projectId.getText();
                Validate.notEmpty(project, "projectId is null");
                Validate.notEmpty(dataSourceTable.getText(), "dataSourceTable is null");

                DefaultListModel model = (DefaultListModel) dimensionList.getModel();
                for (Dimension_ ddd : InformixDbConn.queryGetDaminsion(dataSourceTable.getText(), project)) {
                    model.addElement(ddd);
                }
            }
        });

        swingUtil.addAction("add.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                // Validate.notEmpty(tableName.getText(),
                // "tableName is null");
                Validate.notEmpty(category.getText(), "category is null");
                Validate.notEmpty(dimensionName.getText(), "dimensionName is null");
                Validate.notEmpty(dataSourceTable.getText(), "dataSourceTable is null");
                // Validate.notEmpty(reportId.getText(),
                // "reportId is null");

                String report_id = StringUtils.defaultString(reportId.getText(), projectId.getText());

                String tName = tableName.getText();
                if (StringUtils.isEmpty(tName)) {
                    tName = randomTableName();
                }

                DefaultListModel model = (DefaultListModel) dimensionList.getModel();
                model.addElement(new Dimension_(dataSourceTable.getText(), tName, category.getText(),
                        (String) rscdzzzzIdIndex.getSelectedItem(), dimensionName.getText(), report_id));
            }
        });

        swingUtil.addAction("create.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {

                String project = projectId.getText();
                Validate.notEmpty(project, "projectId is null");
                Validate.notNull(baseDir, "exportDir is null");

                File destDir = new File(baseDir, project);

                Map<String, Object> map = new HashMap<String, Object>();

                List<Map<String, String>> llist = new ArrayList<Map<String, String>>();

                int idx = 2;
                int categoryId = 1;
                DefaultListModel model = (DefaultListModel) dimensionList.getModel();
                for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) {
                    Dimension_ di = (Dimension_) enu.nextElement();

                    Map mmm = new HashMap();
                    mmm.put("rscdpg0901", di.dataSourceTable);//
                    mmm.put("rscdpg0901a", di.tableName);//
                    mmm.put("rscdpg0901a_category", di.category);//
                    mmm.put("rscdpg0901a_report_id", di.reportId);//
                    mmm.put("rscdzzzz_id", di.idIndex);//
                    mmm.put("rscdpg0901a_dname", di.dimensionName);//
                    llist.add(mmm);
                }

                map.put("PROJECT_ID", project);
                map.put("RSCDPG0901", llist);
                map.put("rscdpg0901", dataSourceTable.getText());

                ConfigCopy.getInstance().applyBaseDir(baseDir).applyProjectId(project).execute();

                Dimension.getInstance()//
                        .applyDestDir(destDir.getAbsolutePath())//
                        .applyParameter(map)//
                        .execute();

                JOptionPaneUtil.newInstance().iconInformationMessage()
                        .showMessageDialog(project + " create completed!!\r\n dir : " //
                                + destDir.getAbsolutePath(), project);

                Desktop.getDesktop().open(destDir);
            }
        });

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:gtu._work.etc._3DSMovieRenamer.java

private void initGUI() {
    try {/*from   ww  w  .j a  v a 2s .  c  om*/
        final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);

        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("3DS Rename");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("vid list", null, jPanel1, null);
                {
                    openDir = new JButton();
                    jPanel1.add(openDir, BorderLayout.NORTH);
                    openDir.setText("open dir");
                    openDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            swingUtil.invokeAction("openDir.actionPerformed", evt);
                        }
                    });
                }
                {
                    ListModel vidListModel = new DefaultListModel();
                    vidList = new JList();
                    jPanel1.add(vidList, BorderLayout.CENTER);
                    vidList.setModel(vidListModel);
                    vidList.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                            swingUtil.invokeAction("vidList.mouseClicked", evt);
                        }
                    });
                    vidList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            swingUtil.invokeAction("vidList.keyPressed", evt);
                        }
                    });
                }
                {
                    jPanel3 = new JPanel();
                    jPanel1.add(jPanel3, BorderLayout.SOUTH);
                    jPanel3.setPreferredSize(new java.awt.Dimension(445, 34));
                    {
                        renameText = new JTextField();
                        jPanel3.add(renameText);
                        renameText.setPreferredSize(new java.awt.Dimension(187, 24));
                    }
                    {
                        renameBtn = new JButton();
                        jPanel3.add(renameBtn);
                        renameBtn.setText("rename");
                        renameBtn.setPreferredSize(new java.awt.Dimension(106, 24));
                        renameBtn.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction("renameBtn.mouseClicked", evt);
                            }
                        });
                    }
                    {
                        forceChange = new JCheckBox();
                        jPanel3.add(forceChange);
                        forceChange.setText("force");
                        forceChange.setPreferredSize(new java.awt.Dimension(64, 21));
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("copy", null, jPanel2, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    {
                        ListModel copyToListModel = new DefaultListModel();
                        copyToList = new JList();
                        jScrollPane1.setViewportView(copyToList);
                        copyToList.setModel(copyToListModel);
                        copyToList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction("copyToList.mouseClicked", evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("BT Movie", null, jPanel4, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel4.add(jScrollPane2, BorderLayout.WEST);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(254, 355));
                    {
                        btDirTree = new JTree();
                        jScrollPane2.setViewportView(btDirTree);
                        btDirTree.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction(evt);
                            }
                        });
                        btDirTree.addPropertyChangeListener(new PropertyChangeListener() {
                            public void propertyChange(PropertyChangeEvent evt) {
                                swingUtil.invokeAction(evt);
                            }
                        });
                        JTreeUtil.newInstance(btDirTree).fileSystem(DEFAULT_BT_DIR);
                    }
                }
                {
                    jPanel5 = new JPanel();
                    BorderLayout jPanel5Layout = new BorderLayout();
                    jPanel5.setLayout(jPanel5Layout);
                    jPanel4.add(jPanel5, BorderLayout.CENTER);
                    {
                        jScrollPane3 = new JScrollPane();
                        jPanel5.add(jScrollPane3, BorderLayout.CENTER);
                        jScrollPane3.setPreferredSize(new java.awt.Dimension(427, 355));
                        {
                            DefaultListModel btMovListModel = new DefaultListModel();
                            btMovList = new JList();
                            jScrollPane3.setViewportView(btMovList);
                            btMovList.setModel(btMovListModel);
                            btMovList.addMouseListener(new MouseAdapter() {
                                public void mouseClicked(MouseEvent evt) {
                                    swingUtil.invokeAction(evt);
                                }
                            });
                            btMovList.addKeyListener(new KeyAdapter() {
                                public void keyPressed(KeyEvent evt) {
                                    JListUtil.newInstance(btMovList).defaultJListKeyPressed(evt);
                                }
                            });
                        }
                    }
                }
            }
            {
                jPanel6 = new JPanel();
                FlowLayout jPanel6Layout = new FlowLayout();
                jTabbedPane1.addTab("common", null, jPanel6, null);
                jPanel6.setLayout(jPanel6Layout);
                {
                    execute3dsVidTransfer = new JButton();
                    jPanel6.add(execute3dsVidTransfer);
                    execute3dsVidTransfer.setText("execute 3ds video transfer");
                    execute3dsVidTransfer.setPreferredSize(new java.awt.Dimension(207, 42));
                    execute3dsVidTransfer.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            String bat = "C:/apps/_movie/3DSVideov1.00/3DS Video.exe";
                            try {
                                Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", bat));
                            } catch (IOException e) {
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
                {
                    openMovieAppDir = new JButton();
                    jPanel6.add(openMovieAppDir);
                    openMovieAppDir.setText("open movie app dir");
                    openMovieAppDir.setPreferredSize(new java.awt.Dimension(207, 42));
                    openMovieAppDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                Desktop.getDesktop().open(new File("C:/apps/_movie"));
                            } catch (IOException e) {
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
            }
            {
                jPanel7 = new JPanel();
                BorderLayout jPanel7Layout = new BorderLayout();
                jTabbedPane1.addTab("fake rename", null, jPanel7, null);
                jPanel7.setLayout(jPanel7Layout);
                {
                    openFakeRenameDir = new JButton();
                    jPanel7.add(openFakeRenameDir, BorderLayout.NORTH);
                    openFakeRenameDir.setText("open dir");
                    openFakeRenameDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JCommonUtil._jFileChooser_selectDirectoryOnly();
                            if (file != null) {
                                DefaultListModel model = new DefaultListModel();
                                for (File f : file.listFiles()) {
                                    model.addElement(f);
                                }
                                openFakeRenameDirList.setModel(model);
                            }
                        }
                    });
                }
                {
                    DefaultListModel openFakeRenameDirListModel = new DefaultListModel();
                    openFakeRenameDirList = new JList();
                    jPanel7.add(openFakeRenameDirList, BorderLayout.CENTER);
                    openFakeRenameDirList.setModel(openFakeRenameDirListModel);
                    openFakeRenameDirList.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                            File file = (File) JListUtil.getLeadSelectionObject(openFakeRenameDirList);
                            try {
                                Process process = Runtime.getRuntime()
                                        .exec(String.format("cmd /c call \"%s\"", file));
                                InputStream ins = process.getInputStream();
                                while (ins.read() != -1) {
                                    //TODO
                                }
                                ins.close();
                                System.out.println("done...");
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    openFakeRenameDirList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            JListUtil.newInstance(openFakeRenameDirList).defaultJListKeyPressed(evt);
                        }
                    });
                }
                {
                    jPanel8 = new JPanel();
                    jPanel7.add(jPanel8, BorderLayout.SOUTH);
                    jPanel8.setPreferredSize(new java.awt.Dimension(681, 43));
                    {
                        openFakeRenameDir_newName = new JTextField();
                        jPanel8.add(openFakeRenameDir_newName);
                        openFakeRenameDir_newName.setPreferredSize(new java.awt.Dimension(287, 27));
                    }
                    {
                        fakeRenameExecute = new JButton();
                        jPanel8.add(fakeRenameExecute);
                        fakeRenameExecute.setText("execute");
                        fakeRenameExecute.setPreferredSize(new java.awt.Dimension(95, 27));
                        fakeRenameExecute.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                DefaultListModel model = (DefaultListModel) openFakeRenameDirList.getModel();
                                //TODO
                            }
                        });
                    }
                }
            }

            swingUtil.addAction("copyToList.mouseClicked", new Action() {
                public void action(EventObject evt) throws Exception {
                    try {
                        if (((MouseEvent) evt).getButton() == 3) {
                            JMenuItem reloadMenu = new JMenuItem();
                            reloadMenu.setText("reload SD card directory");
                            reloadMenu.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                    DefaultListModel copyToListModel = new DefaultListModel();
                                    for (final File f : load3DSDir.listFiles(new FilenameFilter() {
                                        public boolean accept(File paramFile, String paramString) {
                                            if (paramFile.isDirectory()
                                                    && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) {
                                                return true;
                                            }
                                            return false;
                                        }
                                    })) {
                                        copyToListModel.addElement(f);
                                    }
                                    copyToList.setModel(copyToListModel);
                                }
                            });
                            JMenuItem copyAllToMenu = new JMenuItem();
                            {
                                copyAllToMenu.setText(
                                        String.format("move %d vids to...", vidList.getModel().getSize()));
                                final File toDir = (File) JListUtil.getLeadSelectionObject(copyToList);
                                if (toDir == null || !toDir.exists() || !toDir.isDirectory()) {
                                    copyAllToMenu.setEnabled(false);
                                }
                                if (vidList.getModel().getSize() == 0) {
                                    copyAllToMenu.setText("copy no file...");
                                    copyAllToMenu.setEnabled(false);
                                }
                                copyAllToMenu.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent e) {
                                        DefaultListModel model = JListUtil.newInstance(vidList).getModel();
                                        if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil
                                                .newInstance().iconWaringMessage().confirmButtonYesNo()
                                                .showConfirmDialog("are you sure copy files : "
                                                        + model.getSize() + "\n to dir : " + toDir,
                                                        "COPY VIDS")) {
                                            return;
                                        }
                                        for (int ii = 0; ii < model.getSize(); ii++) {
                                            File src = (File) model.getElementAt(ii);
                                            src.renameTo(new File(toDir, src.getName()));
                                        }
                                        JOptionPaneUtil.newInstance().iconInformationMessage()
                                                .showMessageDialog("copy completed!", "SUCCESS");
                                        loadDirVids();
                                    }
                                });
                            }

                            JPopupMenuUtil.newInstance(copyToList).applyEvent((MouseEvent) evt)
                                    .addJMenuItem(reloadMenu, copyAllToMenu).show();
                        }
                    } catch (Exception ex) {
                        JCommonUtil.handleException(ex);
                    }
                }
            });
            swingUtil.addAction("openDir.actionPerformed", new Action() {
                public void action(EventObject evt) throws Exception {
                    File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                            .getApproveSelectedFile();
                    if (file == null) {
                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                .showMessageDialog("dir not corrent!, set desktop", getTitle());
                        loadDir = FileUtil.DESKTOP_DIR;
                    } else {
                        loadDir = file;
                    }
                    loadDirVids();
                }
            });
            swingUtil.addAction("vidList.mouseClicked", new Action() {
                //                    final String player = "C:/Program Files (x86)/GRETECH/GomPlayer/GOM.EXE";

                public void action(EventObject evt) throws Exception {
                    int pos = -1;
                    if ((pos = vidList.getLeadSelectionIndex()) == -1) {
                        return;
                    }
                    MouseEvent mevt = (MouseEvent) evt;

                    final File selectItem = (File) vidList.getModel().getElementAt(pos);

                    List<JMenuItem> menuList = new ArrayList<JMenuItem>();
                    JMenuItem simpleRenamer = new JMenuItem();
                    final String simpleRenamePrefix = RandomUtil.upperCase(3);
                    simpleRenamer.setText("Rename : " + simpleRenamePrefix);
                    simpleRenamer.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent paramActionEvent) {
                            String value = StringUtils.defaultString(JOptionPaneUtil.newInstance()
                                    .showInputDialog("3 char prefix?", "AVI PREFIX"), simpleRenamePrefix);
                            if (value != null && value.matches("[a-zA-Z]{3}")) {
                                selectItem.renameTo(getNewFile(selectItem.getParentFile(), value));
                                loadDirVids();
                            } else {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("prefix is not correct!", "ERROR");
                            }
                        }
                    });
                    menuList.add(simpleRenamer);
                    if (load3DSDir == null) {
                        reload3DSDir();
                        if (load3DSDir == null) {
                            JMenuItem disable = new JMenuItem();
                            disable.setText("MOVE : SD card is not set!");
                            disable.setEnabled(false);
                            menuList.add(disable);
                        }
                    } else {
                        for (final File f : load3DSDir.listFiles(new FilenameFilter() {
                            public boolean accept(File paramFile, String paramString) {
                                if (paramFile.isDirectory() && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) {
                                    return true;
                                }
                                return false;
                            }
                        })) {
                            JMenuItem copyTo = new JMenuItem();
                            copyTo.setText("MOVE : " + f.getName());
                            copyTo.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent paramActionEvent) {
                                    if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION == JOptionPaneUtil
                                            .newInstance().iconQuestionMessage().confirmButtonYesNo()
                                            .showConfirmDialog(//
                                                    "are you sure move file\n" + //
                                    selectItem + "\n" + //
                                    "to\n" + //
                                    "dir : " + f + "  ??"//
                                    , "COPY FILE")) {

                                        File copyToNewDirFile = new File(f, selectItem.getName());
                                        if (copyToNewDirFile.exists()) {
                                            JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(
                                                    "target dir file already exist!, need rename!",
                                                    "FILE ALREADY EXIST");
                                            return;
                                        }
                                        selectItem.renameTo(copyToNewDirFile);
                                        loadDirVids();

                                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                                .showMessageDialog("move completed!", "MOVE FILE");
                                    }
                                }
                            });
                            menuList.add(copyTo);
                        }
                    }
                    JPopupMenuUtil.newInstance(vidList).applyEvent(mevt)
                            .addJMenuItem(menuList.toArray(new JMenuItem[menuList.size()])).show();

                    if (mevt.getClickCount() != 2) {
                        return;
                    }
                    String clkItemPath = selectItem.getAbsolutePath();
                    String command = "cmd /c call \"" + clkItemPath + "\"";
                    System.out.println(command);
                    Runtime.getRuntime().exec(command);
                }
            });
            swingUtil.addAction("vidList.keyPressed", new Action() {
                public void action(EventObject evt) throws Exception {
                    JListUtil.newInstance(vidList).defaultJListKeyPressed(evt);
                }
            });
            swingUtil.addAction("renameBtn.mouseClicked", new Action() {

                Pattern aviNamePattern = Pattern.compile("^([a-zA-Z]{3})_\\d{4}\\.[aA][vV][iI]$");

                public void action(EventObject evt) throws Exception {
                    String name = StringUtils.defaultIfEmpty(renameText.getText(), RandomUtil.upperCase(3));
                    System.out.println("name = " + name + ", force : " + forceChange.isSelected());
                    if (!name.matches("[a-zA-Z]{3}")) {
                        renameText.setText("");
                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                .showMessageDialog("rename must eng 3 char!", "ERROR");
                        return;
                    }
                    DefaultListModel model = (DefaultListModel) vidList.getModel();
                    boolean matchOk = false;
                    if (model.size() != 0) {
                        File oldFile = null;
                        Matcher matcher = null;
                        for (int ii = 0; ii < model.getSize(); ii++) {
                            oldFile = (File) model.getElementAt(ii);

                            if (!oldFile.exists()) {
                                JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(
                                        "file not exeist : \n" + oldFile.getAbsolutePath(), getTitle());
                                return;
                            }
                            matcher = aviNamePattern.matcher(oldFile.getName());
                            matchOk = matcher.find();
                            System.out.println("matchOk = " + matchOk);
                            if (matchOk && !forceChange.isSelected()) {
                                oldFile.renameTo(getNewFile(oldFile.getParentFile(), matcher.group(1)));
                            } else {
                                oldFile.renameTo(getNewFile(oldFile.getParentFile(), name));
                            }
                        }
                        JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog("success!",
                                getTitle());
                    }
                    loadDirVids();
                }
            });

            ToolTipManager.sharedInstance().setInitialDelay(0);
            swingUtil.addAction(btMovList, MouseEvent.class, new Action() {
                public void action(EventObject evt) throws Exception {
                    final File file = (File) JListUtil.getLeadSelectionObject(btMovList);
                    if (JMouseEventUtil.buttonLeftClick(1, evt)) {
                        btMovList.setToolTipText(
                                DateFormatUtils.format(file.lastModified(), "yyyy/MM/dd HH:mm:ss") + " length:"
                                        + (file.length() / 1024) + "k");
                    }

                    final Object[] objects = btMovList.getSelectedValues();
                    JPopupMenuUtil.newInstance(btMovList).applyEvent(evt)//
                            .addJMenuItem("move out", (objects != null && objects.length > 0),
                                    new ActionListener() {
                                        public void actionPerformed(ActionEvent paramActionEvent) {
                                            List<File> list = new ArrayList<File>();
                                            for (Object val : objects) {
                                                list.add((File) val);
                                            }
                                            if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure move file from\n" + list.toString().replace(',', '\n')
                                                            + "\nto\n" + DEFAULT_BT_DIR,
                                                    "MOVE")) {
                                                return;
                                            }
                                            StringBuilder sb = new StringBuilder();
                                            File moveTo = null;
                                            for (File file : list) {
                                                sb.append((file.renameTo(
                                                        moveTo = new File(DEFAULT_BT_DIR, file.getName()))
                                                        && moveTo.exists()) ? "" : file + "\n");
                                            }
                                            JCommonUtil._jOptionPane_showMessageDialog_info(
                                                    sb.length() == 0 ? "move success!" : "move failed!\n" + sb);
                                        }
                                    })
                            .addJMenuItem("delete this", file.exists(), new ActionListener() {
                                public void actionPerformed(ActionEvent paramActionEvent) {
                                    if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                            "sure delete file \n" + file, "DELETE")) {
                                        return;
                                    }
                                    boolean result = file.delete();
                                    System.out.println("!!!!!" + result + "..." + file.exists());
                                    JCommonUtil._jOptionPane_showMessageDialog_info(
                                            result ? "delete success!" : "delete failed!");
                                }
                            }).show();

                    if (JMouseEventUtil.buttonLeftClick(2, evt)) {
                        Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", file));
                    }
                }
            });
            swingUtil.addAction(btDirTree, MouseEvent.class, new Action() {

                File getSingleFile() {
                    return ((JFile) JTreeUtil.newInstance(btDirTree).getSelectItem().getUserObject()).getFile();
                }

                public void action(EventObject evt) throws Exception {
                    int selectCount = btDirTree.getSelectionModel().getSelectionCount();
                    if (selectCount == 1) {
                        final File file = getSingleFile();
                        JPopupMenuUtil.newInstance(btDirTree).applyEvent(evt).addJMenuItem("delete this",
                                selectCount == 1 && file.exists(), new ActionListener() {
                                    public void actionPerformed(ActionEvent paramActionEvent) {
                                        if (file.isFile()) {
                                            if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure delete FILE : \n" + file, "WARNING")) {
                                                file.delete();
                                                JCommonUtil._jOptionPane_showMessageDialog_info(
                                                        (file.exists() ? "delete failed!" : "delete success!"));
                                            }
                                        }
                                        if (file.isDirectory()) {
                                            StringBuilder sb = new StringBuilder();
                                            if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure delete DIR : \n" + file, "WARNING")) {
                                                List<Boolean> delL = new ArrayList<Boolean>();
                                                for (File f : file.listFiles()) {
                                                    if (fileExtensionPattern.matcher(f.getName()).find()
                                                            || f.length() > 1000000L) {
                                                        if (!JCommonUtil
                                                                ._JOptionPane_showConfirmDialog_yesNoOption(
                                                                        "delete this : \n" + f,
                                                                        "CHECK AGAIN")) {
                                                            continue;
                                                        }
                                                        delL.add(f.delete());
                                                    }
                                                    delL.add(f.delete());
                                                }
                                                for (File f : file.listFiles()) {
                                                    if (f.exists()) {
                                                        sb.append(f + "\n");
                                                    }
                                                }
                                                System.out.println("delL.contains(false)==================>"
                                                        + delL.contains(false));
                                            }
                                            if (!file.delete()) {
                                                sb.append(file + "\n");
                                            }
                                            JCommonUtil._jOptionPane_showMessageDialog_info(
                                                    sb.length() > 0 ? "delete failed!\nlist:\n" + sb
                                                            : "delete success!");
                                            if (sb.length() == 0) {
                                                DefaultMutableTreeNode node = JTreeUtil.newInstance(btDirTree)
                                                        .getSelectItem();
                                                System.out.println(
                                                        JTreeUtil.newInstance(btDirTree).removeNode(node));
                                            }
                                        }
                                    }
                                }).addJMenuItem("open dir", new ActionListener() {
                                    public void actionPerformed(ActionEvent paramActionEvent) {
                                        File openTarget = file;
                                        if (file.isFile()) {
                                            openTarget = file.getParentFile();
                                        }
                                        try {
                                            Desktop.getDesktop().open(openTarget);
                                        } catch (IOException e) {
                                            JCommonUtil.handleException(e);
                                        }
                                    }
                                }).show();
                    }
                }
            });
            swingUtil.addAction(btDirTree, PropertyChangeEvent.class, new Action() {
                public void action(EventObject evt) throws Exception {
                    List<File> list = new ArrayList<File>();
                    for (DefaultMutableTreeNode node : JTreeUtil.newInstance(btDirTree).getSelectItems()) {
                        JFile jfile = (JFile) node.getUserObject();
                        if (jfile.getFile().isDirectory()) {
                            for (File f : jfile.getFile().listFiles(new FilenameFilter() {
                                public boolean accept(File paramFile, String paramString) {
                                    return fileExtensionPattern.matcher(paramString).find();
                                }
                            })) {
                                System.out.println(f.getName() + "...." + f.length());
                                list.add(f);
                            }
                        }
                    }
                    Collections.sort(list, new Comparator<File>() {
                        public int compare(File paramT1, File paramT2) {
                            return paramT1.lastModified() > paramT2.lastModified() ? -1 : 1;
                        }
                    });
                    btMovList.setModel(JListUtil.createModel(list.iterator()));
                }
            });
        }
        this.setSize(702, 422);

        loadDirVids();
        reload3DSDir();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:gov.nih.nci.cacis.common.util.ExtractSchematron.java

private QName typeQName(XSTypeDefinition type) {
    return new QName(type.getNamespace(), StringUtils.defaultString(type.getName(), "##ANONYMOUS##"));
}

From source file:net.duckling.ddl.web.controller.LynxEditPageController.java

@RequestMapping(params = "func=validateFileName")
public void validateFileName(HttpServletRequest request, HttpServletResponse response) {
    int rid = Integer.parseInt(StringUtils.defaultString(request.getParameter("rid"), "0"));
    JSONObject o = new JSONObject();
    if (rid == 0) {
        o.put("result", false);
        o.put("message", "??");
    } else {/*from www. ja  va2s . c o  m*/
        String fileName = request.getParameter("fileName");
        Resource resource = resourceService.getResource(rid);
        int parentRid = resource.getBid();
        if (!resourceOperateService.canUseFileName(VWBContext.getCurrentTid(), parentRid, rid,
                resource.getItemType(), fileName)) {
            o.put("result", false);
            o.put("message", "?????");
        } else {
            o.put("result", true);
        }
    }
    JsonUtil.writeJSONObject(response, o);
}