Exemplo n.º 1
0
 @NotNull
 public String getNewProjectFilePath() {
   if (myWizardContext.getProjectStorageFormat() == StorageScheme.DEFAULT) {
     return myWizardContext.getProjectFileDirectory()
         + File.separator
         + myWizardContext.getProjectName()
         + ProjectFileType.DOT_DEFAULT_EXTENSION;
   } else {
     return myWizardContext.getProjectFileDirectory();
   }
 }
Exemplo n.º 2
0
 @NonNls
 public String getModuleFilePath() {
   return myWizardContext.getProjectFileDirectory()
       + File.separator
       + myWizardContext.getProjectName()
       + ModuleFileType.DOT_DEFAULT_EXTENSION;
 }
 private static NamePathComponent initNamePathComponent(WizardContext context) {
   NamePathComponent component =
       new NamePathComponent(
           IdeBundle.message("label.project.name"),
           IdeBundle.message("label.project.files.location"),
           IdeBundle.message(
               "title.select.project.file.directory",
               IdeBundle.message("project.new.wizard.project.identification")),
           IdeBundle.message(
               "description.select.project.file.directory",
               StringUtil.capitalize(
                   IdeBundle.message("project.new.wizard.project.identification"))),
           true,
           false);
   final String baseDir = context.getProjectFileDirectory();
   final String projectName = context.getProjectName();
   final String initialProjectName =
       projectName != null
           ? projectName
           : ProjectWizardUtil.findNonExistingFileName(baseDir, "untitled", "");
   component.setPath(
       projectName == null ? (baseDir + File.separator + initialProjectName) : baseDir);
   component.setNameValue(initialProjectName);
   component.getNameComponent().select(0, initialProjectName.length());
   return component;
 }
Exemplo n.º 4
0
 @NotNull
 public String getNewCompileOutput() {
   final String projectFilePath = myWizardContext.getProjectFileDirectory();
   @NonNls String path = myWizardContext.getCompilerOutputDirectory();
   if (path == null) {
     path =
         StringUtil.endsWithChar(projectFilePath, '/')
             ? projectFilePath + "out"
             : projectFilePath + "/out";
   }
   return path;
 }
 public void prepare(@NotNull WizardContext context) {
   myControl.reset();
   String pathToUse = context.getProjectFileDirectory();
   myControl.setLinkedProjectPath(pathToUse);
   doPrepare(context);
 }
  public void bindModuleSettings() {

    myNamePathComponent
        .getNameComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myModuleNameChangedByUser) {
                  setModuleName(myNamePathComponent.getNameValue());
                }
              }
            });

    myModuleContentRoot.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);

    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myContentRootChangedByUser) {
                  setModuleContentRoot(myNamePathComponent.getPath());
                }
              }
            });
    myModuleName
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myModuleNameDocListenerEnabled) {
                  myModuleNameChangedByUser = true;
                }
                String path = getDefaultBaseDir(myWizardContext);
                final String moduleName = getModuleName();
                if (path.length() > 0
                    && !Comparing.strEqual(moduleName, myNamePathComponent.getNameValue())) {
                  path += "/" + moduleName;
                }
                if (!myContentRootChangedByUser) {
                  final boolean f = myModuleNameChangedByUser;
                  myModuleNameChangedByUser = true;
                  setModuleContentRoot(path);
                  myModuleNameChangedByUser = f;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(path);
                }
              }
            });
    myModuleContentRoot
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myContentRootDocListenerEnabled) {
                  myContentRootChangedByUser = true;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(getModuleContentRoot());
                }
                if (!myModuleNameChangedByUser) {
                  final String path = FileUtil.toSystemIndependentName(getModuleContentRoot());
                  final int idx = path.lastIndexOf("/");

                  boolean f = myContentRootChangedByUser;
                  myContentRootChangedByUser = true;

                  boolean i = myImlLocationChangedByUser;
                  myImlLocationChangedByUser = true;

                  setModuleName(idx >= 0 ? path.substring(idx + 1) : "");

                  myContentRootChangedByUser = f;
                  myImlLocationChangedByUser = i;
                }
              }
            });

    myModuleFileLocation.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.file.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.file.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);
    myModuleFileLocation
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myImlLocationDocListenerEnabled) {
                  myImlLocationChangedByUser = true;
                }
              }
            });
    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(myNamePathComponent.getPath());
                }
              }
            });
    if (myWizardContext.isCreatingNewProject()) {
      setModuleName(myNamePathComponent.getNameValue());
      setModuleContentRoot(myNamePathComponent.getPath());
      setImlFileLocation(myNamePathComponent.getPath());
    } else {
      final Project project = myWizardContext.getProject();
      assert project != null;
      VirtualFile baseDir = project.getBaseDir();
      if (baseDir != null) { // e.g. was deleted
        final String baseDirPath = baseDir.getPath();
        String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, "untitled", "");
        String contentRoot = baseDirPath + "/" + moduleName;
        if (!Comparing.strEqual(project.getName(), myWizardContext.getProjectName())
            && !myWizardContext.isCreatingNewProject()
            && myWizardContext.getProjectName() != null) {
          moduleName =
              ProjectWizardUtil.findNonExistingFileName(
                  myWizardContext.getProjectFileDirectory(), myWizardContext.getProjectName(), "");
          contentRoot = myWizardContext.getProjectFileDirectory();
        }
        setModuleName(moduleName);
        setModuleContentRoot(contentRoot);
        setImlFileLocation(contentRoot);
        myModuleName.select(0, moduleName.length());
      }
    }
  }
  public ProjectNameWithTypeStep(
      final WizardContext wizardContext, StepSequence sequence, final WizardMode mode) {
    super(wizardContext, mode);
    mySequence = sequence;
    myAdditionalContentPanel.add(
        myModulePanel,
        new GridBagConstraints(
            0,
            GridBagConstraints.RELATIVE,
            1,
            1,
            1,
            1,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    myHeader.setVisible(myWizardContext.isCreatingNewProject() && !isCreateFromTemplateMode());
    myCreateModuleCb.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            UIUtil.setEnabled(myInternalPanel, myCreateModuleCb.isSelected(), true);
            fireStateChanged();
          }
        });
    myCreateModuleCb.setSelected(true);
    if (!myWizardContext.isCreatingNewProject()) {
      myInternalPanel.setBorder(null);
    }
    myModuleDescriptionPane.setContentType(UIUtil.HTML_MIME);
    myModuleDescriptionPane.addHyperlinkListener(
        new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              try {
                BrowserUtil.launchBrowser(e.getURL().toString());
              } catch (IllegalThreadStateException ex) {
                // it's nnot a problem
              }
            }
          }
        });
    myModuleDescriptionPane.setEditable(false);

    final DefaultListModel defaultListModel = new DefaultListModel();
    for (ModuleBuilder builder : ModuleBuilder.getAllBuilders()) {
      defaultListModel.addElement(builder);
    }
    myTypesList.setModel(defaultListModel);
    myTypesList.setSelectionModel(new PermanentSingleSelectionModel());
    myTypesList.setCellRenderer(
        new DefaultListCellRenderer() {
          public Component getListCellRendererComponent(
              final JList list,
              final Object value,
              final int index,
              final boolean isSelected,
              final boolean cellHasFocus) {
            final Component rendererComponent =
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            final ModuleBuilder builder = (ModuleBuilder) value;
            setIcon(builder.getBigIcon());
            setDisabledIcon(builder.getBigIcon());
            setText(builder.getPresentableName());
            return rendererComponent;
          }
        });
    myTypesList.addListSelectionListener(
        new ListSelectionListener() {
          @SuppressWarnings({"HardCodedStringLiteral"})
          public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
              return;
            }

            final ModuleBuilder typeSelected = (ModuleBuilder) myTypesList.getSelectedValue();

            final StringBuilder sb = new StringBuilder("<html><body><font face=\"Verdana\" ");
            sb.append(SystemInfo.isMac ? "" : "size=\"-1\"").append('>');
            sb.append(typeSelected.getDescription()).append("</font></body></html>");

            myModuleDescriptionPane.setText(sb.toString());

            boolean focusOwner = myTypesList.isFocusOwner();
            fireStateChanged();
            if (focusOwner) {
              SwingUtilities.invokeLater(
                  new Runnable() {
                    public void run() {
                      myTypesList.requestFocusInWindow();
                    }
                  });
            }
          }
        });
    myTypesList.setSelectedIndex(0);
    new DoubleClickListener() {
      @Override
      protected boolean onDoubleClick(MouseEvent e) {
        myWizardContext.requestNextStep();
        return true;
      }
    }.installOn(myTypesList);

    final Dimension preferredSize = calcTypeListPreferredSize(ModuleBuilder.getAllBuilders());
    final JBScrollPane pane = IJSwingUtilities.findParentOfType(myTypesList, JBScrollPane.class);
    pane.setPreferredSize(preferredSize);
    pane.setMinimumSize(preferredSize);

    myNamePathComponent
        .getNameComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myModuleNameChangedByUser) {
                  setModuleName(myNamePathComponent.getNameValue());
                }
              }
            });

    myModuleContentRoot.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.content.root.chooser.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);

    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myContentRootChangedByUser) {
                  setModuleContentRoot(myNamePathComponent.getPath());
                }
              }
            });
    myModuleName
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myModuleNameDocListenerEnabled) {
                  myModuleNameChangedByUser = true;
                }
                String path = getDefaultBaseDir(wizardContext);
                final String moduleName = getModuleName();
                if (path.length() > 0
                    && !Comparing.strEqual(moduleName, myNamePathComponent.getNameValue())) {
                  path += "/" + moduleName;
                }
                if (!myContentRootChangedByUser) {
                  final boolean f = myModuleNameChangedByUser;
                  myModuleNameChangedByUser = true;
                  setModuleContentRoot(path);
                  myModuleNameChangedByUser = f;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(path);
                }
              }
            });
    myModuleContentRoot
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myContentRootDocListenerEnabled) {
                  myContentRootChangedByUser = true;
                }
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(myModuleContentRoot.getText());
                }
                if (!myModuleNameChangedByUser) {
                  final String path =
                      FileUtil.toSystemIndependentName(myModuleContentRoot.getText());
                  final int idx = path.lastIndexOf("/");

                  boolean f = myContentRootChangedByUser;
                  myContentRootChangedByUser = true;

                  boolean i = myImlLocationChangedByUser;
                  myImlLocationChangedByUser = true;

                  setModuleName(idx >= 0 ? path.substring(idx + 1) : "");

                  myContentRootChangedByUser = f;
                  myImlLocationChangedByUser = i;
                }
              }
            });

    myModuleFileLocation.addBrowseFolderListener(
        ProjectBundle.message("project.new.wizard.module.file.chooser.title"),
        ProjectBundle.message("project.new.wizard.module.file.description"),
        myWizardContext.getProject(),
        BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR);
    myModuleFileLocation
        .getTextField()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (myImlLocationDocListenerEnabled) {
                  myImlLocationChangedByUser = true;
                }
              }
            });
    myNamePathComponent
        .getPathComponent()
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                if (!myImlLocationChangedByUser) {
                  setImlFileLocation(myNamePathComponent.getPath());
                }
              }
            });
    if (wizardContext.isCreatingNewProject()) {
      setModuleName(myNamePathComponent.getNameValue());
      setModuleContentRoot(myNamePathComponent.getPath());
      setImlFileLocation(myNamePathComponent.getPath());
    } else {
      final Project project = wizardContext.getProject();
      assert project != null;
      VirtualFile baseDir = project.getBaseDir();
      if (baseDir != null) { // e.g. was deleted
        final String baseDirPath = baseDir.getPath();
        String moduleName = ProjectWizardUtil.findNonExistingFileName(baseDirPath, "untitled", "");
        String contentRoot = baseDirPath + "/" + moduleName;
        if (!Comparing.strEqual(project.getName(), wizardContext.getProjectName())
            && !wizardContext.isCreatingNewProject()
            && wizardContext.getProjectName() != null) {
          moduleName =
              ProjectWizardUtil.findNonExistingFileName(
                  wizardContext.getProjectFileDirectory(), wizardContext.getProjectName(), "");
          contentRoot = wizardContext.getProjectFileDirectory();
        }
        setModuleName(moduleName);
        setModuleContentRoot(contentRoot);
        setImlFileLocation(contentRoot);
        myModuleName.select(0, moduleName.length());
      }
    }

    if (isCreateFromTemplateMode()) {
      replaceModuleTypeOptions(new JPanel());
    } else {
      final AnAction arrow =
          new AnAction() {
            @Override
            public void actionPerformed(AnActionEvent e) {
              if (e.getInputEvent() instanceof KeyEvent) {
                final int code = ((KeyEvent) e.getInputEvent()).getKeyCode();
                if (!myCreateModuleCb.isSelected()) return;
                int i = myTypesList.getSelectedIndex();
                if (code == KeyEvent.VK_DOWN) {
                  if (++i == myTypesList.getModel().getSize()) return;
                } else if (code == KeyEvent.VK_UP) {
                  if (--i == -1) return;
                }
                myTypesList.setSelectedIndex(i);
              }
            }
          };
      CustomShortcutSet shortcutSet = new CustomShortcutSet(KeyEvent.VK_UP, KeyEvent.VK_DOWN);
      arrow.registerCustomShortcutSet(shortcutSet, myNamePathComponent.getNameComponent());
      arrow.registerCustomShortcutSet(shortcutSet, myModuleName);
    }
  }