package eu.modelwriter.marker.ui.internal.wizards.markerwizard;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.wizard.Wizard;

import eu.modelwriter.marker.MarkerActivator;
import eu.modelwriter.marker.internal.MarkElementUtilities;
import eu.modelwriter.marker.typing.internal.CreateMarkerWithType;

public class MarkerWizard extends Wizard {

  private MarkerPage page;
  private ISelection selection;
  private IFile file;
  private IMarker marker;

  public MarkerWizard(ISelection selection, IFile file) {
    super();
    this.selection = selection;
    this.file = file;
  }

  public MarkerWizard(IMarker marker) {
    this.marker = marker;
  }

  @Override
  public String getWindowTitle() {
    return "Marking with Tag";
  }

  @Override
  public void addPages() {
    page = new MarkerPage();
    super.addPages();
    this.addPage(page);
  }

  @Override
  public boolean performFinish() {
    if (MarkerPage.markTreeViewer.getTree().getSelection().length == 1) {
      if (MarkerPage.markTreeViewer.getTree().getSelection()[0].getText().endsWith("{abs}")) {
        MessageDialog dialog =
            new MessageDialog(MarkerActivator.getShell(), "Marker Type Information", null,
                "Selected type is not appropriate because it is marked as Abstact",
                MessageDialog.INFORMATION, new String[] {"OK"}, 0);
        dialog.open();
        return false;
      }
      if (!MarkerPage.markTreeViewer.getTree().getItems()[0]
          .equals(MarkerPage.markTreeViewer.getTree().getSelection()[0])) {
        if (this.selection != null) {
          CreateMarkerWithType.createMarker(file, selection,
              MarkerPage.markTreeViewer.getTree().getSelection()[0].getText());
          MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(),
              "Marker Type Information", null, "Marker has been created with selected type",
              MessageDialog.INFORMATION, new String[] {"OK"}, 0);
          dialog.open();
        } else {
          MarkElementUtilities.setType(marker,
              MarkerPage.markTreeViewer.getTree().getSelection()[0].getText());
          MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(),
              "Marker Type Information", null, "Selected type added to selected marker",
              MessageDialog.INFORMATION, new String[] {"OK"}, 0);
          dialog.open();
        }
        return true;
      } else {
        MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(),
            "Marker Type Information", null, "Please select a valid marker type.",
            MessageDialog.INFORMATION, new String[] {"OK"}, 0);
        dialog.open();
        return false;
      }
    } else {
      MessageDialog dialog =
          new MessageDialog(MarkerActivator.getShell(), "Marker Type Information", null,
              "Please select one marker type.", MessageDialog.INFORMATION, new String[] {"OK"}, 0);
      dialog.open();
      return false;
    }
  }
}

@@ -54,24 +54,48 @@
 kerwizard;%0A%0A
+import java.util.List;%0A%0A
 import org.e
@@ -166,16 +166,63 @@
 Marker;%0A
+import org.eclipse.core.runtime.CoreException;%0A
 import o
@@ -453,16 +453,69 @@
 lities;%0A
+import eu.modelwriter.marker.internal.MarkerFactory;%0A
 import e
@@ -2260,32 +2260,519 @@
        %7D else %7B%0A
+          try %7B%0A            Object groupId = marker.getAttribute(MarkElementUtilities.GROUP_ID);%0A            if (groupId != null) %7B%0A              List%3CIMarker%3E list =%0A                  MarkerFactory.findMarkersByGroupId(marker.getResource(), (String) groupId);%0A              for (IMarker iMarker : list) %7B%0A                MarkElementUtilities.setType(iMarker,%0A                    MarkerPage.markTreeViewer.getTree().getSelection()%5B0%5D.getText());%0A              %7D%0A            %7D else %7B%0A    
           MarkEl
@@ -2798,24 +2798,28 @@
 ype(marker,%0A
+    
             
@@ -2878,32 +2878,129 @@
 %5B0%5D.getText());%0A
+            %7D%0A          %7D catch (CoreException e) %7B%0A            e.printStackTrace();%0A          %7D%0A
           Messag

Add type to existing marker command is updated. If this command triggered from text which marked as mark all then all the group is setting for selected marker type.