Search in sources :

Example 1 with VariableInsertionDialog

use of org.eclipse.wst.common.snippets.internal.VariableInsertionDialog in project liferay-ide by liferay.

the class TaglibVariableItemHelper method getInsertString.

public static String getInsertString(Shell host, IEditorPart editor, ISnippetItem item, boolean clearModality) {
    if (item == null) {
        return "";
    }
    String insertString = null;
    if (ListUtil.isNotEmpty(item.getVariables())) {
        VariableInsertionDialog dialog = new TaglibVariableInsertionDialog(host, editor, clearModality);
        dialog.setItem(item);
        // The editor itself influences the insertion's actions, so we
        // can't
        // allow the active editor to be changed.
        // Disabling the parent shell achieves psuedo-modal behavior
        // without
        // locking the UI under Linux
        int result = Window.CANCEL;
        try {
            if (clearModality) {
                host.setEnabled(false);
                dialog.addDisposeListener(new DisposeListener() {

                    public void widgetDisposed(DisposeEvent arg0) {
                        /*
								 * The parent shell must be reenabled when the
								 * dialog disposes, otherwise it won't automatically
								 * receive focus.
								 */
                        host.setEnabled(true);
                    }
                });
            }
            result = dialog.open();
        } catch (Exception t) {
            SnippetsUIPlugin.logError(t);
        } finally {
            if (clearModality) {
                host.setEnabled(true);
            }
        }
        if (result == Window.OK) {
            insertString = dialog.getPreparedText();
        }
    } else {
        insertString = item.getContentString();
    }
    return insertString;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) VariableInsertionDialog(org.eclipse.wst.common.snippets.internal.VariableInsertionDialog) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Aggregations

DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 VariableInsertionDialog (org.eclipse.wst.common.snippets.internal.VariableInsertionDialog)1