Search in sources :

Example 1 with CategorySelectionDialog

use of org.obeonetwork.dsl.requirement.design.selection.CategorySelectionDialog in project InformationSystem by ObeoNetwork.

the class RequirementsServices method copyCategory.

/**
 * CopyCategory.
 *
 * @param category
 */
public void copyCategory(Category category) {
    Shell shell = getShell();
    CategorySelectionDialog dlg = new CategorySelectionDialog(shell, "Copy a category", "Select a container for the new category");
    dlg.setInput(SessionManager.INSTANCE.getSession(category));
    dlg.setInitialSelection(category.eContainer());
    if (dlg.open() == Window.OK) {
        Object selectedObject = dlg.getFirstResult();
        if (selectedObject instanceof CategoriesContainer) {
            CategoriesContainer newContainer = (CategoriesContainer) selectedObject;
            // Check if there are referenced objects
            boolean keepReferencedObject = false;
            if (!category.getReferencedObject().isEmpty()) {
                keepReferencedObject = MessageDialog.openQuestion(shell, "Referenced objects", "Do you want to keep the referenced objects ?");
            }
            // Copy object
            Category newCategory = EcoreUtil.copy(category);
            newCategory.setId(getNewIdForCopiedCategory(newContainer, newCategory));
            if (!keepReferencedObject) {
                newCategory.getReferencedObject().clear();
            }
            // Add to parent
            addToCategoriesContainer(newContainer, newCategory);
        }
    }
    ;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) CategoriesContainer(org.obeonetwork.dsl.requirement.CategoriesContainer) Category(org.obeonetwork.dsl.requirement.Category) CategorySelectionDialog(org.obeonetwork.dsl.requirement.design.selection.CategorySelectionDialog) EObject(org.eclipse.emf.ecore.EObject)

Example 2 with CategorySelectionDialog

use of org.obeonetwork.dsl.requirement.design.selection.CategorySelectionDialog in project InformationSystem by ObeoNetwork.

the class RequirementsServices method moveCategory.

/**
 * Move Category.
 *
 * @param category
 */
public void moveCategory(Category category) {
    Shell shell = getShell();
    CategorySelectionDialog dlg = new CategorySelectionDialog(shell, "Move a category", "Select a new container for the category", category);
    dlg.setInput(SessionManager.INSTANCE.getSession(category));
    dlg.setInitialSelection(category.eContainer());
    if (dlg.open() == Window.OK) {
        Object selectedObject = dlg.getFirstResult();
        if (selectedObject instanceof CategoriesContainer) {
            CategoriesContainer newContainer = (CategoriesContainer) selectedObject;
            // Add to parent
            addToCategoriesContainer(newContainer, category);
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) CategoriesContainer(org.obeonetwork.dsl.requirement.CategoriesContainer) CategorySelectionDialog(org.obeonetwork.dsl.requirement.design.selection.CategorySelectionDialog) EObject(org.eclipse.emf.ecore.EObject)

Example 3 with CategorySelectionDialog

use of org.obeonetwork.dsl.requirement.design.selection.CategorySelectionDialog in project InformationSystem by ObeoNetwork.

the class RequirementsServices method copyRequirement.

/**
 * Copy Requirement.
 *
 * @param requirement
 */
public void copyRequirement(Requirement requirement) {
    Shell shell = getShell();
    CategorySelectionDialog dlg = new CategorySelectionDialog(shell, "Copy a requirement", "Select a container for the new requirement");
    dlg.setInput(SessionManager.INSTANCE.getSession(requirement));
    dlg.setInitialSelection(requirement.eContainer());
    dlg.setValidator(new ISelectionStatusValidator() {

        public IStatus validate(Object[] selection) {
            if (selection.length > 0 && selection[0] instanceof Category) {
                return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
            }
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Select a category");
        }
    });
    if (dlg.open() == Window.OK) {
        Object selectedObject = dlg.getFirstResult();
        if (selectedObject instanceof Category) {
            Category newContainer = (Category) selectedObject;
            // Check if there are referenced objects
            boolean keepReferencedObject = false;
            if (!requirement.getReferencedObject().isEmpty()) {
                keepReferencedObject = MessageDialog.openQuestion(shell, "Referenced objects", "Do you want to keep the referenced objects ?");
            }
            // Copy object
            Requirement newRequirement = EcoreUtil.copy(requirement);
            newRequirement.setId(getNewIdForCopiedRequirement(newContainer, newRequirement));
            if (!keepReferencedObject) {
                newRequirement.getReferencedObject().clear();
            }
            // Add to parent
            newContainer.getRequirements().add(newRequirement);
        }
    }
    ;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ObjectWithRequirement(org.obeonetwork.tools.requirement.ui.decorators.ObjectWithRequirement) Requirement(org.obeonetwork.dsl.requirement.Requirement) Shell(org.eclipse.swt.widgets.Shell) IStatus(org.eclipse.core.runtime.IStatus) Category(org.obeonetwork.dsl.requirement.Category) CategorySelectionDialog(org.obeonetwork.dsl.requirement.design.selection.CategorySelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) EObject(org.eclipse.emf.ecore.EObject)

Example 4 with CategorySelectionDialog

use of org.obeonetwork.dsl.requirement.design.selection.CategorySelectionDialog in project InformationSystem by ObeoNetwork.

the class RequirementsServices method moveRequirement.

/**
 * move Requirement.
 *
 * @param requirement
 */
public void moveRequirement(Requirement requirement) {
    Shell shell = getShell();
    CategorySelectionDialog dlg = new CategorySelectionDialog(shell, "Move a requirement", "Select a new container for the requirement");
    dlg.setInput(SessionManager.INSTANCE.getSession(requirement));
    dlg.setInitialSelection(requirement.eContainer());
    dlg.setValidator(new ISelectionStatusValidator() {

        public IStatus validate(Object[] selection) {
            if (selection.length > 0 && selection[0] instanceof Category) {
                return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
            }
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Select a category");
        }
    });
    if (dlg.open() == Window.OK) {
        Object selectedObject = dlg.getFirstResult();
        if (selectedObject instanceof Category) {
            Category newContainer = (Category) selectedObject;
            // change parent
            newContainer.getRequirements().add(requirement);
        }
    }
    ;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Shell(org.eclipse.swt.widgets.Shell) IStatus(org.eclipse.core.runtime.IStatus) Category(org.obeonetwork.dsl.requirement.Category) CategorySelectionDialog(org.obeonetwork.dsl.requirement.design.selection.CategorySelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)4 Shell (org.eclipse.swt.widgets.Shell)4 CategorySelectionDialog (org.obeonetwork.dsl.requirement.design.selection.CategorySelectionDialog)4 Category (org.obeonetwork.dsl.requirement.Category)3 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ISelectionStatusValidator (org.eclipse.ui.dialogs.ISelectionStatusValidator)2 CategoriesContainer (org.obeonetwork.dsl.requirement.CategoriesContainer)2 Requirement (org.obeonetwork.dsl.requirement.Requirement)1 ObjectWithRequirement (org.obeonetwork.tools.requirement.ui.decorators.ObjectWithRequirement)1