Search in sources :

Example 1 with KotlinMemberSelectionPanel

use of org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberSelectionPanel in project kotlin by JetBrains.

the class MoveKotlinNestedClassesDialog method initMemberInfo.

private void initMemberInfo(@NotNull final List<KtClassOrObject> elementsToMove) {
    List<KotlinMemberInfo> memberInfos = CollectionsKt.mapNotNull(originalClass.getDeclarations(), new Function1<KtDeclaration, KotlinMemberInfo>() {

        @Override
        public KotlinMemberInfo invoke(KtDeclaration declaration) {
            if (!(declaration instanceof KtClassOrObject))
                return null;
            KotlinMemberInfo memberInfo = new KotlinMemberInfo((KtClassOrObject) declaration, false);
            memberInfo.setChecked(elementsToMove.contains(declaration));
            return memberInfo;
        }
    });
    KotlinMemberSelectionPanel selectionPanel = new KotlinMemberSelectionPanel(getTitle(), memberInfos, null);
    memberTable = selectionPanel.getTable();
    MemberInfoModelImpl memberInfoModel = new MemberInfoModelImpl();
    memberInfoModel.memberInfoChanged(new MemberInfoChange<KtNamedDeclaration, KotlinMemberInfo>(memberInfos));
    selectionPanel.getTable().setMemberInfoModel(memberInfoModel);
    selectionPanel.getTable().addMemberInfoChangeListener(memberInfoModel);
    membersInfoPanel.add(selectionPanel, BorderLayout.CENTER);
}
Also used : KotlinMemberSelectionPanel(org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberSelectionPanel) KotlinMemberInfo(org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberInfo)

Example 2 with KotlinMemberSelectionPanel

use of org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberSelectionPanel in project kotlin by JetBrains.

the class MoveKotlinTopLevelDeclarationsDialog method initMemberInfo.

private void initMemberInfo(@NotNull final Set<KtNamedDeclaration> elementsToMove, @NotNull List<KtFile> sourceFiles) {
    final List<KotlinMemberInfo> memberInfos = CollectionsKt.map(getAllDeclarations(sourceFiles), new Function1<KtNamedDeclaration, KotlinMemberInfo>() {

        @Override
        public KotlinMemberInfo invoke(KtNamedDeclaration declaration) {
            KotlinMemberInfo memberInfo = new KotlinMemberInfo(declaration, false);
            memberInfo.setChecked(elementsToMove.contains(declaration));
            return memberInfo;
        }
    });
    KotlinMemberSelectionPanel selectionPanel = new KotlinMemberSelectionPanel(getTitle(), memberInfos, null);
    memberTable = selectionPanel.getTable();
    MemberInfoModelImpl memberInfoModel = new MemberInfoModelImpl();
    memberInfoModel.memberInfoChanged(new MemberInfoChange<KtNamedDeclaration, KotlinMemberInfo>(memberInfos));
    selectionPanel.getTable().setMemberInfoModel(memberInfoModel);
    selectionPanel.getTable().addMemberInfoChangeListener(memberInfoModel);
    selectionPanel.getTable().addMemberInfoChangeListener(new MemberInfoChangeListener<KtNamedDeclaration, KotlinMemberInfo>() {

        private boolean shouldUpdateFileNameField(final Collection<KotlinMemberInfo> changedMembers) {
            if (!tfFileNameInPackage.isEnabled())
                return true;
            Collection<KtNamedDeclaration> previousDeclarations = CollectionsKt.filterNotNull(CollectionsKt.map(memberInfos, new Function1<KotlinMemberInfo, KtNamedDeclaration>() {

                @Override
                public KtNamedDeclaration invoke(KotlinMemberInfo info) {
                    return changedMembers.contains(info) != info.isChecked() ? info.getMember() : null;
                }
            }));
            String suggestedText = previousDeclarations.isEmpty() ? "" : MoveUtilsKt.guessNewFileName(previousDeclarations);
            return tfFileNameInPackage.getText().equals(suggestedText);
        }

        @Override
        public void memberInfoChanged(MemberInfoChange<KtNamedDeclaration, KotlinMemberInfo> event) {
            updatePackageDirectiveCheckBox();
            updateFileNameInPackageField();
            // Update file name field only if it user hasn't changed it to some non-default value
            if (shouldUpdateFileNameField(event.getChangedMembers())) {
                updateSuggestedFileName();
            }
        }
    });
    memberInfoPanel.add(selectionPanel, BorderLayout.CENTER);
}
Also used : KotlinMemberInfo(org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberInfo) KotlinMemberSelectionPanel(org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberSelectionPanel) KtNamedDeclaration(org.jetbrains.kotlin.psi.KtNamedDeclaration)

Aggregations

KotlinMemberInfo (org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberInfo)2 KotlinMemberSelectionPanel (org.jetbrains.kotlin.idea.refactoring.memberInfo.KotlinMemberSelectionPanel)2 KtNamedDeclaration (org.jetbrains.kotlin.psi.KtNamedDeclaration)1