protected void copyAction() {
    CopyContextAction action = new CopyContextAction();
    IStructuredSelection selection = (IStructuredSelection) availableContextsViewer.getSelection();
    if (selection.isEmpty()) {
      return;
    }

    Object element = selection.getFirstElement();
    if (element instanceof Context) {
      Context sourceContext = (Context) element;
      try {

        InputDialog dialog =
            new InputDialog(
                getShell(),
                Messages.CustomizationDialog_enterConfigurationName,
                Messages.CustomizationDialog_enterConfigurationName,
                Messages.CustomizationDialog_copyOf + sourceContext.getName(),
                new IInputValidator() {

                  public String isValid(final String newText) {
                    if (newText.trim().equals("")) { // $NON-NLS-1$
                      return Messages.CustomizationDialog_configurationNameNotEmpty;
                    }
                    if (ConfigurationManager.instance.getContext(newText) != null) {
                      return Messages.CustomizationDialog_configurationWithSameNameExists;
                    }
                    return null;
                  }
                });
        dialog.setTitle(Messages.CustomizationDialog_configurationName);
        int result = dialog.open();
        if (result == Window.OK) {
          String targetName = dialog.getText();
          action.copy(sourceContext, targetName, false);
          availableContextsViewer.setInput(ConfigurationManager.instance.getContexts());
        }
      } catch (IOException ex) {
        Activator.log.error(ex);
      }
    }
  }
  protected void deleteAction() {
    RemoveContextAction action = new RemoveContextAction();
    IStructuredSelection selection = (IStructuredSelection) availableContextsViewer.getSelection();
    if (selection.isEmpty()) {
      return;
    }

    Object element = selection.getFirstElement();
    if (element instanceof Context) {
      Context sourceContext = (Context) element;
      if (ConfigurationManager.instance.isPlugin(sourceContext)) {
        Activator.log.warn(Messages.CustomizationDialog_cannotDeletePluginContext);
        // Plugin context cannot be deleted
        return;
      }

      MessageDialog dialog =
          new MessageDialog(
              getShell(),
              Messages.CustomizationDialog_deleteContext,
              null,
              Messages.CustomizationDialog_deleteContextConfirmation1
                  + sourceContext.getName()
                  + Messages.CustomizationDialog_deleteContextConfirmation2,
              MessageDialog.CONFIRM,
              new String[] {
                IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL
              },
              2);
      int result = dialog.open();
      if (result == 0) { // 0 is "Yes" (It is *not* the same 0 as Window.OK)
        action.removeContext(sourceContext);
        availableContextsViewer.setInput(ConfigurationManager.instance.getContexts());
      }
    }
  }
  @Override
  public boolean performFinish() {
    if (generator == null || contexts == null || contexts.isEmpty() || layoutGenerator == null) {
      return false;
    }

    ConfigurationManager configManager = ConfigurationManager.instance;

    for (Context context : contexts) {
      Tab defaultTab = ContextsFactory.eINSTANCE.createTab();
      defaultTab.setId(context.getName().toLowerCase());
      defaultTab.setLabel(context.getName());
      defaultTab.setPriority(100);
      context.getTabs().add(defaultTab);

      FieldSelection fieldSelection = selectFieldsPage.getFieldSelection();

      //		URI contextURI = context.eResource().getURI();
      //		Resource selectionResource =
      // context.eResource().getResourceSet().createResource(URI.createURI(context.getName() +
      // "FieldSelection.xmi").resolve(contextURI)); //$NON-NLS-1$
      //		selectionResource.getContents().add(fieldSelection);
      //		try {
      //			selectionResource.save(null);
      //		} catch (IOException ex) {
      //			Activator.log.error("Couldn't persist the field selection model", ex); //$NON-NLS-1$
      //		}

      layoutGenerator.setGenerator(generator);

      for (View view : context.getViews()) {
        if (view.getConstraints().size() == 0) {
          continue;
        }

        List<PropertyEditor> editors = new LinkedList<PropertyEditor>();

        for (DataContextElement element : getAllContextElements(view.getDatacontexts())) {
          for (Property property : element.getProperties()) {
            if (isSelected(fieldSelection, property, view.getElementMultiplicity() != 1)) {
              PropertyEditor editor = UiFactory.eINSTANCE.createPropertyEditor();
              editor.setProperty(property);
              editor.setWidgetType(configManager.getDefaultEditorType(property));
              editors.add(editor);
              ValueAttribute input = UiFactory.eINSTANCE.createValueAttribute();
              input.setName("input"); // $NON-NLS-1$
              input.setValue("{Binding}"); // $NON-NLS-1$
              editor.getAttributes().add(input);
            }
          }
        }

        List<Section> generatedSections = layoutGenerator.layoutElements(editors, view);
        defaultTab.getSections().addAll(generatedSections);
        view.getSections().addAll(generatedSections);
        context.getViews().add(view);
      }

      int i = 1;
      for (Tab tab : context.getTabs()) {
        i += tab.getSections().size();
      }
      final int numberOfSections = i;
      try {
        setNeedsProgressMonitor(true);
        final Context currentContext = context;
        getContainer()
            .run(
                true,
                true,
                new IRunnableWithProgress() {

                  public void run(IProgressMonitor monitor)
                      throws InvocationTargetException, InterruptedException {
                    monitor.beginTask(
                        Messages.CreateContextWizard_propertyViewGenerationJobName
                            + currentContext.getName(),
                        numberOfSections + 1);
                    monitor.worked(1);

                    try {
                      currentContext.eResource().save(Collections.EMPTY_MAP);

                      monitor.worked(1);
                      for (Tab tab : currentContext.getTabs()) {
                        for (Section section : tab.getSections()) {
                          if (monitor.isCanceled()) {
                            return;
                          }
                          section.getWidget().eResource().save(Collections.EMPTY_MAP);
                          monitor.worked(1);
                        }
                      }
                    } catch (IOException ex) {
                      Activator.log.error(ex);
                      return;
                    }
                    monitor.done();
                  }
                });
      } catch (InvocationTargetException ex) {
        Activator.log.error(ex);
      } catch (InterruptedException ex) {
        Activator.log.error(ex);
      }
    }

    return true;
  }