Search in sources :

Example 1 with ModuleSpecifierSelectionDialog

use of org.eclipse.n4js.ui.dialog.ModuleSpecifierSelectionDialog in project n4js by eclipse.

the class N4JSNewClassifierWizardPage method openModuleSpecifierDialog.

@Override
public void openModuleSpecifierDialog(Shell shell) {
    ModuleSpecifierSelectionDialog dialog = new ModuleSpecifierSelectionDialog(shell, getModel().getProject().append(getModel().getSourceFolder()));
    if (!getModel().getEffectiveModuleSpecifier().isEmpty()) {
        String initialSelectionSpecifier = getModel().getEffectiveModuleSpecifier();
        String fileExtension = getModel().computeFileLocation().getFileExtension();
        if (fileExtension != null) {
            dialog.setDefaultFileExtension(fileExtension);
        }
        dialog.setInitialSelection(initialSelectionSpecifier);
    }
    dialog.open();
    Object result = dialog.getFirstResult();
    if (result instanceof String) {
        IPath specifierPath = new Path((String) result);
        String fileExtension = specifierPath.getFileExtension();
        // If the selected module specifier is a file
        if (fileExtension != null && !fileExtension.isEmpty()) {
            // and its file extension suggests a different external value than the model
            if (fileExtension.equals(N4JSGlobals.N4JSD_FILE_EXTENSION) != getModel().isDefinitionFile()) {
                // toggle the external value of the model
                getModel().setDefinitionFile(!getModel().isDefinitionFile());
            }
            specifierPath = specifierPath.removeFileExtension();
        }
        // If the last segment corresponds with the non-empty interface name remove it
        if (specifierPath.segmentCount() > 0 && specifierPath.removeFileExtension().lastSegment().equals(getModel().getName()) && !getModel().getName().isEmpty()) {
            if (specifierPath.segmentCount() > 1) {
                specifierPath = specifierPath.removeLastSegments(1).addTrailingSeparator();
            } else {
                specifierPath = specifierPath.removeLastSegments(1);
            }
        }
        getModel().setModuleSpecifier(specifierPath.toString());
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ModuleSpecifierSelectionDialog(org.eclipse.n4js.ui.dialog.ModuleSpecifierSelectionDialog)

Example 2 with ModuleSpecifierSelectionDialog

use of org.eclipse.n4js.ui.dialog.ModuleSpecifierSelectionDialog in project n4js by eclipse.

the class WorkspaceWizardPage method openModuleSpecifierDialog.

/**
 * Open the dialog to select a module specifier
 *
 * @param shell
 *            The Shell to open the dialog in
 */
public void openModuleSpecifierDialog(Shell shell) {
    ModuleSpecifierSelectionDialog dialog = new ModuleSpecifierSelectionDialog(shell, model.getProject().append(model.getSourceFolder()));
    if (!model.getModuleSpecifier().isEmpty()) {
        String initialSelectionSpecifier = model.getModuleSpecifier();
        dialog.setInitialSelection(initialSelectionSpecifier);
    }
    dialog.open();
    Object result = dialog.getFirstResult();
    if (result instanceof String) {
        IPath specifierPath = new Path((String) result);
        model.setModuleSpecifier(specifierPath.removeFileExtension().toString());
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ModuleSpecifierSelectionDialog(org.eclipse.n4js.ui.dialog.ModuleSpecifierSelectionDialog)

Aggregations

IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 ModuleSpecifierSelectionDialog (org.eclipse.n4js.ui.dialog.ModuleSpecifierSelectionDialog)2