Skip to content
Manuel Mauky edited this page Mar 13, 2017 · 3 revisions

IntelliJ IDEA

We are planning to create an IDEA plugin for mvvmFX (see the current state at #339).

File Templates

A recurring task when creating applications with mvvmFX is to create classes for the View, ViewModel and a FXML file for each view component. To simplify this process you can use these file templates in IntelliJ IDEA.

Add File Templates to IDEA

  • Go to Settings -> Editor -> File and Code Templates.
  • Add a new file template by pressing the + button.
  • Name: "mvvmFX ViewModel", Extension: "java"

For ViewModels:

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import de.saxsys.mvvmfx.ViewModel;

#parse("File Header.java")
public class ${NAME}ViewModel implements ViewModel {
}

For FxmlViews:

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.InjectViewModel;

#parse("File Header.java")
public class ${NAME}View implements FxmlView<${NAME}ViewModel> {

    @InjectViewModel
    private ${NAME}ViewModel viewModel;
    
    public void initialize() {
    
    }
}

For JavaViews:

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import de.saxsys.mvvmfx.JavaView;
import de.saxsys.mvvmfx.InjectViewModel;
import javafx.scene.layout.AnchorPane;

#parse("File Header.java")
public class ${NAME} extends AnchorPane implements JavaView<${NAME}ViewModel> {

    @InjectViewModel
    private ${NAME}ViewModel viewModel;
    
    public void initialize() {
    
    }
}

Using the file templates

To use the file templates right click on the package and choose "New" -> "mvvmFX ViewModel" and "mvvmFX FxmlView" or "mvvmFX JavaView". The dialog will ask for a file name. Here you should only enter the domain specific name without the "-ViewModel" or "-View" suffix. Instead of "HelloWorldViewModel" just enter "HelloWorld" for both the ViewModel and the View. The file template will automatically add the correct suffix for you.

Eclipse / Netbeans

At the moment we have no special integration for these IDEs. However, we would be very happy to add introductions for file templates like the ones for IntelliJ here. If you are using Eclipse/Netbeans we highly appreciate your contributions. See #439, #175 and #342