Search in sources :

Example 1 with EntryList

use of com.avast.android.butterknifezelezny.form.EntryList in project android-butterknife-zelezny by avast.

the class InjectAction method showDialog.

protected void showDialog(Project project, Editor editor, ArrayList<Element> elements) {
    PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (file == null) {
        return;
    }
    PsiClass clazz = getTargetClass(editor, file);
    final IButterKnife butterKnife = ButterKnifeFactory.findButterKnifeForPsiElement(project, file);
    if (clazz == null || butterKnife == null) {
        return;
    }
    // get parent classes and check if it's an adapter
    boolean createHolder = false;
    PsiReferenceList list = clazz.getExtendsList();
    if (list != null) {
        for (PsiJavaCodeReferenceElement element : list.getReferenceElements()) {
            if (Definitions.adapters.contains(element.getQualifiedName())) {
                createHolder = true;
            }
        }
    }
    // get already generated injections
    ArrayList<String> ids = new ArrayList<String>();
    PsiField[] fields = clazz.getAllFields();
    String[] annotations;
    String id;
    for (PsiField field : fields) {
        annotations = field.getFirstChild().getText().split(" ");
        for (String annotation : annotations) {
            id = Utils.getInjectionID(butterKnife, annotation.trim());
            if (!Utils.isEmptyString(id)) {
                ids.add(id);
            }
        }
    }
    EntryList panel = new EntryList(project, editor, elements, ids, createHolder, this, this);
    mDialog = new JFrame();
    mDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    mDialog.getRootPane().setDefaultButton(panel.getConfirmButton());
    mDialog.getContentPane().add(panel);
    mDialog.pack();
    mDialog.setLocationRelativeTo(null);
    mDialog.setVisible(true);
}
Also used : ArrayList(java.util.ArrayList) EntryList(com.avast.android.butterknifezelezny.form.EntryList) IButterKnife(com.avast.android.butterknifezelezny.butterknife.IButterKnife)

Aggregations

IButterKnife (com.avast.android.butterknifezelezny.butterknife.IButterKnife)1 EntryList (com.avast.android.butterknifezelezny.form.EntryList)1 ArrayList (java.util.ArrayList)1