Search in sources :

Example 1 with RemoveModuleMessageExtension

use of org.eclipse.wst.server.ui.RemoveModuleMessageExtension in project webtools.servertools by eclipse.

the class ServerUIPlugin method loadRemoveModuleMessageExtensions.

/**
 * Load the remove module message customization extensions.
 */
private static synchronized void loadRemoveModuleMessageExtensions() {
    if (removeModuleMessageExtensions != null)
        return;
    if (Trace.CONFIG) {
        Trace.trace(Trace.STRING_CONFIG, "->- Loading .removeModuleMessageExtensions extension point ->-");
    }
    removeModuleMessageExtensions = new ArrayList<RemoveModuleMessageExtension>();
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] cf = registry.getConfigurationElementsFor(ServerUIPlugin.PLUGIN_ID, "removeModuleMessageExtension");
    for (IConfigurationElement curConfigElement : cf) {
        try {
            RemoveModuleMessageExtension curExtension = (RemoveModuleMessageExtension) curConfigElement.createExecutableExtension("class");
            String serverTypeId = curConfigElement.getAttribute("serverTypeId");
            if (serverTypeId != null) {
                curExtension.setServerTypeId(serverTypeId);
            }
            if (Trace.CONFIG) {
                Trace.trace(Trace.STRING_CONFIG, "  Loaded .removeModuleMessageExtension: " + curConfigElement.getAttribute("id") + ", loaded class=" + curExtension);
            }
            if (curExtension != null)
                removeModuleMessageExtensions.add(curExtension);
        } catch (Throwable t) {
            if (Trace.SEVERE) {
                Trace.trace(Trace.STRING_SEVERE, "  Could not load .removeModuleMessageExtension: " + curConfigElement.getAttribute("id"), t);
            }
        }
    }
    if (Trace.CONFIG) {
        Trace.trace(Trace.STRING_CONFIG, "-<- Done loading .removeModuleMessageExtension extension point -<-");
    }
}
Also used : RemoveModuleMessageExtension(org.eclipse.wst.server.ui.RemoveModuleMessageExtension)

Example 2 with RemoveModuleMessageExtension

use of org.eclipse.wst.server.ui.RemoveModuleMessageExtension in project webtools.servertools by eclipse.

the class PreferenceUtil method confirmModuleRemoval.

public static boolean confirmModuleRemoval(IServerAttributes server, Shell shell, List<IModule> moduleList) {
    // Get preference value to see if the confirmation dialog should appear or not. Default is to show the dialog.
    boolean doNotShowDialog = ServerUIPlugin.getPreferences().getDoNotShowRemoveModuleWarning();
    if (!doNotShowDialog) {
        String message = null;
        String id = server.getServerType().getId();
        RemoveModuleMessageExtension targetExtension = ServerUIPlugin.getRemoveModuleMessageExtension(id);
        String customMessage = null;
        if (moduleList.size() > 0) {
            if (targetExtension != null) {
                customMessage = targetExtension.getConfirmationMessage(server, moduleList.toArray(new IModule[0]));
            }
            // The extension might still return null or an empty string.  If so, then use the default/original message.
            if (customMessage == null || customMessage.length() == 0) {
                if (moduleList.size() == 1) {
                    // Default singular
                    message = Messages.dialogRemoveModuleConfirm;
                } else {
                    // Default plural
                    message = Messages.dialogRemoveModulesConfirm;
                }
            } else {
                message = customMessage;
            }
        }
        MessageDialogWithToggle messageWithToggle = MessageDialogWithToggle.openOkCancelConfirm(shell, Messages.defaultDialogTitle, message, Messages.doNotShowAgain, false, null, null);
        // If cancel is pressed, do not update the preference even if the checkbox changed.
        if (messageWithToggle.getReturnCode() == Window.CANCEL) {
            // Do not remove, return false
            return false;
        }
        // If OK was pressed, then also update the preference
        ServerUIPlugin.getPreferences().setDoNotShowRemoveModuleWarning(messageWithToggle.getToggleState());
    }
    // Proceed with removal
    return true;
}
Also used : RemoveModuleMessageExtension(org.eclipse.wst.server.ui.RemoveModuleMessageExtension) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle)

Example 3 with RemoveModuleMessageExtension

use of org.eclipse.wst.server.ui.RemoveModuleMessageExtension in project webtools.servertools by eclipse.

the class RemoveModuleMessageExtensionTestCase method testRemoveModuleMessageExtension.

public void testRemoveModuleMessageExtension() {
    List<RemoveModuleMessageExtension> extensions = ServerUIPlugin.getRemoveModuleMessageExtensions();
    // Have two from the test plugin
    assertTrue("Remove Message Extensions", extensions.size() >= 1);
    // Test the filter *
    RemoveModuleMessageExtension removeModuleMessageExtensionA = ServerUIPlugin.getRemoveModuleMessageExtension("org.eclipse.wst.server.testA.v1");
    assertNotNull(removeModuleMessageExtensionA);
    String customMessageA = removeModuleMessageExtensionA.getConfirmationMessage(null, null);
    assertTrue("Check Custom Message", RemoveModuleMessageTestExtension.customRemoveMessage.equals(customMessageA));
    // Test the filter .*
    RemoveModuleMessageExtension removeModuleMessageExtensionB = ServerUIPlugin.getRemoveModuleMessageExtension("org.eclipse.wst.server.testB.v1");
    assertNotNull(removeModuleMessageExtensionB);
    String customMessageB = removeModuleMessageExtensionB.getConfirmationMessage(null, null);
    assertTrue("Check Custom Message", RemoveModuleMessageTestExtension.customRemoveMessage.equals(customMessageB));
    // Test exact match
    RemoveModuleMessageExtension removeModuleMessageExtensionC = ServerUIPlugin.getRemoveModuleMessageExtension("org.eclipse.wst.server.testC");
    assertNotNull(removeModuleMessageExtensionC);
    String customMessageC = removeModuleMessageExtensionC.getConfirmationMessage(null, null);
    assertTrue("Check Custom Message", RemoveModuleMessageTestExtension.customRemoveMessage.equals(customMessageC));
}
Also used : RemoveModuleMessageExtension(org.eclipse.wst.server.ui.RemoveModuleMessageExtension)

Aggregations

RemoveModuleMessageExtension (org.eclipse.wst.server.ui.RemoveModuleMessageExtension)3 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)1